Skip to content

Instantly share code, notes, and snippets.

@ShilGen
Last active October 7, 2023 16:50
Show Gist options
  • Save ShilGen/a0f211cc9b0136d3c73b433bd273f13d to your computer and use it in GitHub Desktop.
Save ShilGen/a0f211cc9b0136d3c73b433bd273f13d to your computer and use it in GitHub Desktop.

★ C#

Master заметка

.GetType(); получить тип

% — остаток от деления

по умолчанию используется целочисленное деление, 3 / 2 будет 1

Для получения дробной части:

int a = 5;
int b = 8;
double percent = (double) a / b ;

\n - символ переноса (escape sequence)

⚠️ Конкатенация — операция соединения двух строк. Например, Console.WriteLine("King's " + " Landing");

Интерполяция — способ соединения строк через вставку значений переменных в строку-шаблон с помощью фигурных скобок. Например, $"Hi, {name}!".

Console.WriteLine($"{greeting}, {firstName}!");

Преобразование букв английского алфавита в цифры

  var res = (char)(64+16);
        return res;
 //return string.Format("{0}{1}:{0}{2}","A", 7, 6);
 return string.Format("{0}{1}:{2}{1}","L", 5, "M");

🔗 https://www.techiedelight.com/ru/merge-two-hashsets-in-csharp/

Словари

var keys = new[] {"one", "two", "three"};
var values = new[] {"oneV", "twoV", "threeV"};
var dictionary = keys.Select((k, i)=>(k, i)).ToDictionary(x=>x.k, x=>values[x.i]);
return dictionary["one"];
phoneBook.Add("+123456", "Tom");
// альтернативное добавление
// phoneBook["+123456"] = "Tom";

🔗 https://metanit.com/sharp/tutorial/4.9.php

Коллекции

🔗 https://metanit.com/sharp/tutorial/4.5.php

Tuple Кортежи

🔗 https://learn.microsoft.com/ru-Ru/dotnet/api/system.tuple?view=net-6.0

Структура DateTime

DateTime date = DateTime.Now;

Форматирование даты

DateTime date1 = new DateTime(2015, 7, 20, 18, 30, 25); // год - месяц - день - час - минута - секунда
Console.WriteLine(date1.ToLongDateString()); // 20 июля 2015 г.
Console.WriteLine(date1.ToShortDateString()); // 20.07.2015

Работа с датами и временем

🔗 https://metanit.com/sharp/tutorial/19.1.php


Использование оператора foreach с массивами

https://learn.microsoft.com/ru-ru/dotnet/csharp/programming-guide/arrays/using-foreach-with-arrays


🔝

Master заметка

@ShilGen
Copy link
Author

ShilGen commented Jul 15, 2023

@ShilGen
Copy link
Author

ShilGen commented Aug 10, 2023

@ShilGen
Copy link
Author

ShilGen commented Oct 7, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment