//private static string k = ""; static void Main(string[] args) { /* string j = ""; for (int i = 0; i < 10; i++) { j = i.ToString(); k = i.ToString(); Console.WriteLine(i); if (i == 9) { string l = i.ToString(); } //Console.WriteLine(l); < --error } //Console.WriteLine(i); <-- error Console.WriteLine("Outside of the for: {0}", j); Console.WriteLine("k: {0}", k); HelperMethod(); */ Car car = new Car(); car.DoSomething(); Console.ReadLine(); }
//private static string k = ""; static void Main(string[] args) { /* string j = ""; for (int i = 0; i < 10; i++) { j = i.ToString(); k = i.ToString(); Console.WriteLine(i); if (i == 9) { string l = i.ToString(); // Console.WriteLine("L: " + l); } } Console.WriteLine("Outside of the for: " + j); //Console.WriteLine("K: " + k); helperMethod();*/ Car car = new Car(); car.DoSomething(); Console.ReadLine(); }
static void Main(string[] args) { string j = ""; for (int i = 0; i < 10; i++) { j = i.ToString(); k = i.ToString(); Console.WriteLine(i); if (i == 9) { string l = i.ToString(); } //Console.WriteLine(l); } //Console.WriteLine(i); Console.WriteLine("Outside of the for: " + j); Console.WriteLine("Outside of the for: " + k); HelperMethod(); Car myCar = new Car(); myCar.DoSomething(); Console.ReadLine(); }
static void Main(string[] args) { string j = ""; for (int i = 0; i < 10; i++) { j = i.ToString(); k = i.ToString(); Console.WriteLine(i); if (i == 9) { string l = i.ToString(); } //Console.WriteLine("l: " l); here l wont be accessible as well, only inside the if } //The variable i is not accessible from here, outside the for //Console.WriteLine(i); Console.WriteLine("Outside of the for: " + j); //Console.WriteLine("k: " + k); K will be accessible because it was declared inside the main helperMethod();//calling the method with the value of K Car car = new Car(); car.DoSomething(); Console.ReadLine(); }
//private static string k = ""; static void Main(string[] args) { // string j = ""; // for (int i = 0; i < 10; i++) // { // j = i.ToString(); // k = i.ToString(); // Console.WriteLine(i); // if (i == 9) // { // string l = i.ToString(); // } // } // Console.WriteLine("Outside of the for: " + j); // //Console.WriteLine("k: " + k); // helperMethod(); Car car = new Car(); car.DoSomething(); Console.ReadLine(); }
static void Main(string[] args) { Car myCar = new Car(); myCar.DoSomething(); Console.ReadLine(); }