Advertisement
Felanpro

my first class

Aug 10th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace csharp_youtube_tutorial
  8. {
  9.     //User made class.
  10.     class Person
  11.     {
  12.         //Acces modifiers: public, private, static. public members can be accessed by any class. private can be accessed only in the class the member is in! Static members i dont know really. :)
  13.         public string name = "Charles";
  14.         public int age = 34;
  15.         public string usuall_emotion = "Happy";
  16.  
  17.         public void person_information()
  18.         {
  19.             Console.WriteLine("Name: " + name);
  20.             Console.WriteLine("Age: " + age);
  21.             Console.WriteLine("Ususall emotion: " + usuall_emotion);
  22.         }
  23.     }
  24.  
  25.     //Original class.
  26.     class Program
  27.     {
  28.         public static void Main(string[] args)
  29.         {
  30.             Console.ForegroundColor = ConsoleColor.Red; //Just for stylish<--!-->
  31.  
  32.             Person person_object1 = new Person(); //Syntax for creating an object for a class.
  33.  
  34.             string x = person_object1.name; //object.member
  35.             Console.WriteLine(x);
  36.  
  37.             person_object1.person_information(); //You can also acces methods form classes.
  38.  
  39.  
  40.  
  41.             Console.ReadKey(); //Press a key application ends. //Console[Class] ReadKey()[Function/Method]  
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement