Advertisement
bero_0401

Constant / Read-only

Aug 17th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | Source Code | 0 0
  1.  
  2. using Microsoft.VisualBasic;
  3. using System.Text;
  4.  
  5. namespace CsharpCourse
  6. {
  7.  
  8.     internal class Program
  9.     {
  10.  
  11.         // Constant
  12.         // Must assign value
  13.         // value can not be changed
  14.         // Compile Time Constant: the application replace it with the constant value
  15.         public const string Message = "hello";
  16.  
  17.  
  18.         // Read-only
  19.         // can only be changed into the constructor [ several times ]
  20.         // Run Time Constant
  21.  
  22.         public readonly string _message;
  23.  
  24.         public Program()
  25.         {
  26.  
  27.             _message = "Hello";
  28.         }
  29.  
  30.  
  31.         static void Main(string[] args)
  32.         {
  33.            
  34.  
  35.         }
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement