Advertisement
idroj07

c#Console_ClassPropertiesAccess

Aug 20th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2.  
  3. namespace test //c# in console
  4. {
  5.     class TestClass
  6.     {
  7.         //members
  8.         private int mCod;
  9.  
  10.         //properties
  11.         public int Cod
  12.         {
  13.             get{
  14.                 return mCod;
  15.             }
  16.             set{
  17.                 mCod = value;
  18.             }
  19.         }
  20.         //methods
  21.         private void greetings() // CHANGE TO PUBLIC?
  22.         {
  23.             Console.WriteLine("Hello!!");
  24.         }
  25.     }
  26.     class Program
  27.     {
  28.         static void Main(string[] args)
  29.         {
  30.             void functest() //U can't declare with privacy and outside Main
  31.             {
  32.                 Console.WriteLine("main func test");
  33.             }
  34.             bool i = true;
  35.  
  36.             if(i)
  37.                 Console.WriteLine("Hello World");                
  38.             functest();
  39.  
  40.             //using methods and properties of an internal class
  41.             TestClass.Cod = 3;
  42.             Console.WriteLine(TestClass.Cod + "\n" + TestClass.greetings);
  43.  
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement