Advertisement
bero_0401

classes

Aug 17th, 2024 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | Source Code | 0 0
  1. using Microsoft.VisualBasic;
  2. using System.Text;
  3.  
  4. namespace CsharpCourse
  5. {
  6.     internal class Student
  7.     {
  8.         // automatic implemented property
  9.         public int Id { get; set; }
  10.         public string Name { get; set; }
  11.  
  12.         // Read-only
  13.         public string Description { get; }
  14.  
  15.         // init-only
  16.         public int Age { get; init; }
  17.  
  18.  
  19.         // Id , Name , .. -> backing fields
  20.  
  21.  
  22.         /*
  23.         public int Id  
  24.         {
  25.             get
  26.             {
  27.                 return Id;
  28.             }
  29.             set
  30.             {
  31.                 Id = value;
  32.             }
  33.         }
  34.         */
  35.  
  36.  
  37.         // cto
  38.         public Student()
  39.         {
  40.             Console.WriteLine("Object has been intialized!");
  41.         }
  42.     }
  43.  
  44.     internal class Program
  45.     {
  46.         static void Main(string[] args)
  47.         {
  48.             // built-in class
  49.             // all classes are children to the [ object class ]
  50.             object obj = new object();
  51.            
  52.             // object intialization
  53.             Student s = new Student() { Id = 1  , Name ="Abeer"};
  54.  
  55.  
  56.            
  57.  
  58.  
  59.  
  60.         }
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement