Untitled

 avatar
unknown
plain_text
a year ago
2.5 kB
5
Indexable
internal class Program
{
	private static void Main(string[] args)
	{
		Modifier modifier = new Modifier();

		/*modifier.Name = "Nurbek";
		modifier.Id = 19;

		Console.WriteLine(modifier.Name);
		Console.WriteLine(modifier.Id);*/

		Override simpleOverride = new Override();
		simpleOverride.WriteColorLine("Nurbek is poor programmer", ConsoleColor.Magenta, '%');
		simpleOverride.WriteColorLine("Pizza", ConsoleColor.Cyan);
		simpleOverride.WriteColorLine("Pizza", ConsoleColor.Cyan);
	}
}

//Модификаторы доступа
// class - по умолчанию internal, а составляющие класса - по умолчанию private
public class Modifier
{	
	// поле 
	private string _name;

	// public - доступ во всё решении
	// internal - доступ только в текущем проекте
	// private - доступ только внутри контекста

	// class - может быть только internal или public 

	// Авто-свойства
	public int Id { get; set; } // get и set - это аксессор

	// Полные свойства
	public string Name 
	{
		get 
		{
			if (_name == default)
			{
				return "Имя ещё не указано";
			}
			else
			{
				return _name;
			}
		}
		set 
		{
			if (value == default)
			{
				Console.WriteLine("Некорректо указано имя");
			}
			else
			{
				_name = value; 
			}
		}
	}

	public DateTime GetCurrentTime()
	{
		return new DateTime(2024, 3, 18);
	}


}

//Перегрузка методов
public class Override
{
	public void WriteColorLine(string line, ConsoleColor color)
	{	
		Console.ForegroundColor = color;
		Console.WriteLine(line);
		Console.ResetColor();
	}
	public void WriteColorLine(char preCharacter, string line, ConsoleColor color)
	{
		Console.ForegroundColor = color;
		Console.WriteLine(preCharacter + line);
		Console.ResetColor();
	}
	public void WriteColorLine(string line, ConsoleColor color, char afterCharacter)
	{
		Console.ForegroundColor = color;
		Console.WriteLine(line + afterCharacter);
		Console.ResetColor();
	}
}

// readonly 
public class ReadOnly
{
	//константа для всего класса
	public const int Default = 23;
	//константа для каждого объекта
	public readonly int Number;

	public ReadOnly(int number)
	{
		Number = number;
	}

	public void Reset()
	{
		//Number = 2;
	}
}
Editor is loading...
Leave a Comment