Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace DemoCapsulation
- {
- public class Car
- {
- //полета -> характеристики
- //access modifiers / модификатори за достъп
- //private -> достъпно само в рамките на класа
- //public -> достъпно навсякъде
- //internal -> default modifier
- private string color;
- private int year;
- private string brand;
- //get -> осигурява достъп до стойността на полето
- //set -> можем да задаваме стойност на полето
- public string Color { get; set; }
- public int Year { get; set; }
- public string Brand { get; set; }
- //конструктор -> метод, чрез който създаваме обекти от класа
- public Car()
- {
- //default contructor -> съществува винаги, когато се създаде един клас
- //създава празен обект
- }
- public Car(string color, int year, string brand)
- {
- //нов празен обект
- this.Color = color;
- this.Year = year;
- this.Brand = brand;
- }
- //методи
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement