public bool Lost {get; private set;} = false;
public void MakeLose() {
if(Lost== false) {
Lost = true;
Say("Проиграл");
}
}
x.MakeLoose()
вместо x.Loose = true;
Regex.Replace("a.b.c....", @"[^\.]", "") //в результате будет "......"
var pointsCount = ".a.b.c....".Count(x=>x == '.');
var result = new string('.', pointsCount);
var pointsCount = 0;
foreach(var x in "a.b.c....") {
if(x == '.')
pointsCount++;
}
var result = new string('.', pointsCount);
var pointsCount = 0;
var str = ".a.b.c.";
for(var i=0; i<str.Length;i++) {
if(str[i] == '.')
pointsCount++;
}
var result = new string('.', pointsCount);
var dict = new Dictionary {
["val1"] = new Dictionary {
["set1"] = new [] {35, 30, 39}
}
};
// dict имеет тип Dictionary<string, Dictionary<string, int[]>>
interface ISpeaking {
public void Speak();
}
public class Dog: ISpeaking {
public void Speak() => Console.WriteLine("Гав!");
}
public class Cat: ISpeaking {
public void Speak() => Console.WriteLine("Мяу!");
}
public static void Main() {
ISpeaking[] speakers = new ISpeaking[] {new Cat(), new Dog()};
foreach(ISpeaking speaker in speakers)
speaker.Speak();
}
static void PrintAll(string[] array) {
foreach(var e in array)
Console.WriteLine(e);
}
static void PrintAll(List<string> list) {
foreach(var e in list) { // Дублирование!
Console.WriteLine(e);
}
// Можно использовать и для string[], и для List<string>, и даже для того, о чём мы ещё не знаем!
static void PrintAll(IEnumerable<string> collection) {
foreach(var e in collection) {
Console.WriteLine(e);
}
}
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net5.0/Demo.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
var json = "{\"id\":1,\"number\":42,\"bagGUID\":null}";
var data = JsonSerializer.Deserialize<Barcode>(json);
Console.WriteLine(data!.ToString()); // выведет "Barcode { Id = 1, Number = 42, BagGuid = }"
record Barcode
{
[JsonPropertyName("id")]
public int Id { get; init; }
[JsonPropertyName("number")]
public int Number { get; init; }
[JsonPropertyName("bagGUID")]
public Guid? BagGuid { get; init; }
}