Advertisement
constk

Some C# funny static ctor

Mar 4th, 2021
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. namespace CSharpTest
  5. {
  6.     class Account
  7.     {
  8.         public static int staticValue;
  9.         public int instanceValue;
  10.  
  11.         static Account() => staticValue = 10; // is called once then there is any usage of static value or creating first class instance
  12.         public Account(int value) => instanceValue = value;
  13.  
  14.         public static int StaticVaule { get; set; }
  15.         public int InstanceValue { get; set; }
  16.     }
  17.  
  18.     class Program
  19.     {
  20.         static void Main(string[] args)
  21.         {
  22.             CultureInfo.CurrentCulture = new CultureInfo("en-US", false);
  23.  
  24.             Console.WriteLine(Account.staticValue); // 10
  25.             Account.staticValue = 14;
  26.             Console.WriteLine(Account.staticValue); // 14
  27.  
  28.             Account acc = new Account(100);
  29.             Console.WriteLine(Account.staticValue); // 14
  30.  
  31.             Console.ReadKey();
  32.         }
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement