var buf = new string[reader.FieldCount];
for(var i = 0; i < buf.Length; i++)
buf[i] = reader.GetString(i);
data.Add(buf);
var int1Type = int1.GetType();
var fieldAccessor = int1Type.GetField("hiddenClass2", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic);
var hiddenClass2Value = fieldAccessor.GetValue(int1);
StopCoroutine(spawn());
int result;
switch(something) {
case "a":
result = 1;
break;
case "b":
result = 2;
break;
default:
result = 3;
break;
}
var result = something switch {
"a" => 1,
"b" => 2,
_ => 3
}
using System;
using System.Collections.Generic;
using System.Linq;
namespace App
{
class Application
{
private static List<Record> DB = new();
static void Main()
{
var authorized = Authorize();
if (authorized)
{
Greet();
WorkLoop();
}
else
{
RestrictAccess();
}
BeforeLeave();
}
private static void BeforeLeave()
{
Console.WriteLine("Нажмите любую кнопку, чтобы выйти");
Console.ReadKey();
}
private static void Greet()
{
Console.WriteLine("Доступ разрешён");
Console.WriteLine("Добро пожаловать в систему");
}
private static void RestrictAccess()
{
Console.WriteLine("Доступ заблокирован");
}
private static bool Authorize()
{
Console.WriteLine("Введите пароль");
const string password = "8294";
const int maxAttemptsCount = 3;
var passwordCorrect = false;
for (var i = 0; i < maxAttemptsCount; i++)
{
var input = Console.ReadLine();
if (input == password)
{
passwordCorrect = true;
break;
}
}
return passwordCorrect;
}
private static void WorkLoop()
{
while (true)
{
Console.Clear();
Console.WriteLine(@"
1 - Пополнить БД
2 - Посмотреть БД");
var guess = Console.ReadLine();
switch (guess)
{
case "1":
AddNewRecord();
break;
case "2":
ReadAllRecords();
break;
default:
continue;
}
Console.WriteLine("Нажмите любую кнопку, чтобы венуться в меню");
Console.ReadKey();
}
}
private static void ReadAllRecords()
{
Console.WriteLine();
Console.WriteLine("ID\t Имя\t Уровень\t Страна");
foreach (var record in DB)
{
Console.WriteLine($"{record.Id}\t{record.Name}\t{record.Level}\t{record.Country}");
}
Console.WriteLine(DB.Count);
}
private static IEnumerator<int> sequence = Enumerable.Range(1, int.MaxValue).GetEnumerator();
private static void AddNewRecord()
{
Console.WriteLine("Создание записи");
Console.Write("Введите имя: ");
var name = Console.ReadLine();
Console.Write("Введите уровень: ");
var levelString = Console.ReadLine();
if (!int.TryParse(levelString, out var level))
{
Console.WriteLine("Ошибка. Введено не число. Создание записи прервано.");
return;
}
Console.Write("Введите страну: ");
var country = Console.ReadLine();
sequence.MoveNext();
var id = sequence.Current;
var record = new Record
{
Id = id,
Country = country,
Name = name,
Level = level
};
DB.Add(record);
Console.WriteLine("Запись создана");
}
}
public class Record
{
public int Id { get; init; }
public string Name { get; init; }
public int Level { get; init; }
public string Country { get; init; }
}
}
В то время как переменные принято именовать
public int myNumber = 1;
In addition to the rules, there are a number of identifier naming conventions used throughout the .NET APIs. By convention, C# programs use PascalCase for type names, namespaces, and all public members. In addition, the following conventions are common:
- Interface names start with a capital I.
- Attribute types end with the word Attribute.
- Enum types use a singular noun for non-flags, and a plural noun for flags.
- Identifiers should not contain two consecutive _ characters. Those names are reserved for compiler generated identifiers.