Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace csharp_youtube_tutorial
- {
- class myClass
- {
- public static int count = 0; //A static variable's value is shared among all instances of that class.
- }
- class Program /*An instance of a class is another name for object*/
- {
- public static void Main(string[] args)
- {
- myClass obj1 = new myClass();
- myClass.count += 1; //You can directly acces the static variable from the class.
- Console.WriteLine(myClass.count);
- myClass obj2 = new myClass();
- Console.WriteLine(myClass.count); //This would have printed 1 if we had not set static to count.
- Console.ReadKey(); //Press a key application ends. //Console[Class] ReadKey()[Function/Method]
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement