//Our main method is static so in order to call any non static method //from main method either need to create object of class or make variable or method as static //creating object of class we can handle non static variable using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication7 { public class Program { string b="test"; public void m1() { Console.WriteLine("non static method"); } public static void Main(string[] args) { Program a1 = new Program(); a1.m1(); Console.WriteLine(a1.b); Console.ReadLine(); } } } or declare variable and method as static to call from main method using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication7 { public class Program { static string b="test"; public static void m1() { Console.WriteLine("non static method"); } public static void Main(string[] args) { m1(); Console.WriteLine(b); Console.ReadLine(); } } } | 0 |
By: [email protected] On: Tue May 02 21:40:20 IST 2017 0 0 0 | 0 |
Are You Satisfied :0Yes0No |
//Our main method is static so in order to call any non static method //from main method either need to create object of class or make variable or method as static //creating object of class we can handle non static variable using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication7 { public class Program { string b="test"; public void m1() { Console.WriteLine("non static method"); } public static void Main(string[] args) { Program a1 = new Program(); a1.m1(); Console.WriteLine(a1.b); Console.ReadLine(); } } } or declare variable and method as static to call from main method using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication7 { public class Program { static string b="test"; public static void m1() { Console.WriteLine("non static method"); } public static void Main(string[] args) { m1(); Console.WriteLine(b); Console.ReadLine(); } } } | 0 |
By: [email protected] On: Tue May 02 21:40:58 IST 2017 0 0 0 | 0 |
Are You Satisfied :0Yes0No |
0 | |
By: [email protected] On: Wed May 03 00:27:44 IST 2017 0 0 0 | 0 |
Are You Satisfied :0Yes0No |