0

If I add "public" while defining a variable in main method it shows me error in c#,why?

here is the code class Program { static void Main(string[] args) { public string yourName; Console.WriteLine("What is your name?"); yourName = Console.ReadLine(); Console.WriteLine("Hello {0}", yourName); } }

29th Jun 2018, 4:12 PM
Khushboo Gupta
Khushboo Gupta - avatar
1 Odpowiedź
+ 1
access delimiters like public or private only has sense when declearing them in a class, NOT in a method inside the class. You should rewrite that line before or after the Main method, but inside the class.
29th Jun 2018, 4:17 PM
Bebida Roja
Bebida Roja - avatar