Advertisement
nahidjamalli

Lesson #2

Feb 16th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. namespace MyNamespace
  2. {
  3.     class Program
  4.     {
  5.         struct MyStruct
  6.         {
  7.             public static int countOfCreatedObjects;
  8.             public string name;
  9.         }
  10.  
  11.         static void Main(string[] args)
  12.         {
  13.             MyStruct ms = new MyStruct();
  14.             ms.name = "abc";
  15.             MyStruct.countOfCreatedObjects = 1;
  16.  
  17.             MyStruct ms1 = new MyStruct();
  18.             ms1.name = "xyz";
  19.             MyStruct.countOfCreatedObjects++;
  20.  
  21.             MyStruct ms2 = new MyStruct();
  22.             ms2.name = "abc";
  23.             MyStruct.countOfCreatedObjects++;
  24.  
  25.             MyStruct ms3 = new MyStruct();
  26.             ms3.name = "xyz";
  27.             MyStruct.countOfCreatedObjects++;
  28.  
  29.             System.Console.WriteLine(MyStruct.countOfCreatedObjects);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement