using System.Net;
namespace ConsoleApp;
internal class Program
{
private const int SUCCESS = 0;
private const int COMMAND_LINE_ARGS_ARE_NOT_SPECIFIED = 1;
private const int EXCEPTION_THROWN = 2;
private static Task<int> Main(string[] args)
{
return new Program().Run(args);
}
private async Task<int> Run(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Not enough positional command-line arguments specified!");
return COMMAND_LINE_ARGS_ARE_NOT_SPECIFIED;
}
try
{
foreach (string hostName in args)
{
IPHostEntry hostEntry = await Dns.GetHostEntryAsync(hostName);
DisplayHost(hostEntry);
}
return SUCCESS;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return EXCEPTION_THROWN;
}
}
private void DisplayHost(IPHostEntry hostEntry)
{
Console.WriteLine(hostEntry.HostName);
foreach (var ipAddress in hostEntry.AddressList)
{
Console.WriteLine(ipAddress);
}
Console.WriteLine("---");
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
using static ConsoleApp.ConsoleInput;
namespace ConsoleApp;
public class Program
{
static void Main(string[] args)
{
new Program().Run(args);
}
private void Run(string[] args)
{
Console.WriteLine("Введите данные уравнения"); // Введите данные уравнения
double a = RequestUserInputAsDouble("Введите число a:"); // Введите а
double b = RequestUserInputAsDouble("Введите число b:"); // Введите b
double c = RequestUserInputAsDouble("Введите число c:"); // Введите c
Console.WriteLine("Ваше уравнение: " + a + "x^2 + " + b + "x + " + c + " = 0");
double discriminant = CalculateDiscriminant(a, b, c);
if (discriminant < 0) // Условие, если Дискриминант < 0
{
Console.WriteLine("Нет решений, т.к D < 0 "); // Вывод ответа
}
else if (discriminant > 0) // // Условие, если Дискриминант > 0
{
double x1 = (-b + Math.Sqrt(discriminant)) / (2 * a); // Обьявление переменной х1 и решение
double x2 = (-b - Math.Sqrt(discriminant)) / (2 * a); // Обьявление переменной х2 и решение
Console.WriteLine("Ваш ответ: x1 = " + x1 + " x2 = " + x2); // Вывод ответа
}
else // (D == 0) Условие, если Дискриминант = 0
{
double x1 = (-b + Math.Sqrt(0)) / (2 * a); // Обьявление переменной х1 и решение
double x2 = x1; // Обьявление переменной х2 и решение
Console.WriteLine("Ваш ответ: x2 = x1 = " + x1); // Вывод ответа
}
}
private double CalculateDiscriminant(double a, double b, double c)
{
// Вычисление переменной Дискриминант
return b * b - (4 * a * c);
}
}
using System.Globalization;
namespace ConsoleApp;
internal static class ConsoleInput
{
private static readonly CultureInfo CommaCulture =
new(CultureInfo.InvariantCulture.LCID)
{
NumberFormat = { NumberDecimalSeparator = "," }
};
private static readonly CultureInfo PointCulture =
new(CultureInfo.InvariantCulture.LCID)
{
NumberFormat = { NumberDecimalSeparator = "." }
};
/// <summary>
/// Запросить ввод у пользователя. Если ввод нельзя конвертировать в целевой тип,
/// то ввод будет запрошен повторно. Это обобщённый метод, позволящий реализовать
/// несколько других методов, требующих ввод в определённом формате.
/// </summary>
/// <typeparam name="TResult">
/// Тип результата, который ожидается от метода конвертации.
/// </typeparam>
/// <param name="tryConvert">Ссылка на метод конвертации.</param>
/// <param name="message">
/// Сообщение, которое будет показано пользователю каждый новый запрос ввода значения.
/// </param>
/// <returns></returns>
private static TResult RequestUserInput<TResult>(
Func<string, (bool, TResult)> tryConvert, string? message = null)
where TResult : struct
{
TResult result;
while (true)
{
if (!string.IsNullOrWhiteSpace(message))
{
Console.WriteLine(message);
}
string? line = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(line))
{
var (success, convertedValue) = tryConvert(line);
if (success)
{
result = convertedValue;
break;
}
}
}
return result;
}
/// <summary>
/// Запросить у пользователя ввод числа типа double.
/// Допускается в качестве разделителя "," и ".".
/// </summary>
/// <param name="message">
/// Сообщение, которое будет показано пользователю каждый новый запрос ввода значения.
/// </param>
/// <returns></returns>
public static double RequestUserInputAsDouble(string? message = null)
{
return RequestUserInput(userInput =>
{
CultureInfo culture = CultureInfo.InvariantCulture;
if (userInput.Contains(",")) culture = CommaCulture;
if (userInput.Contains(".")) culture = PointCulture;
return double.TryParse(
userInput, NumberStyles.Float, culture, out var result)
? (true, result)
: (false, 0d);
}, message);
}
// И другие типы в том же духе
public static int RequestUserInputAsInt32(string? message = null)
{
return RequestUserInput(userInput =>
int.TryParse(userInput, out var result)
? (true, result)
: (false, 0),
message);
}
}
FirstReportInvoiceDal[] firstReportInvoice =
{
new () { Id = 1, Number = "" },
new () { Id = 2, Number = "" },
new () { Id = 3, Number = "" },
new () { Id = 4, Number = "" },
new () { Id = 5, Number = "" },
};
SecondReportInvoiceDal[] secondReportInvoice =
{
new () { FirstReportId = 1, Number = "1111N" },
new () { FirstReportId = 2, Number = "2222N" },
new () { FirstReportId = 3, Number = "3333N" },
new () { FirstReportId = 4, Number = "4444N" },
new () { FirstReportId = 5, Number = "5555N" },
};
Id: 1, Number: 1111N
Id: 2, Number: 2222N
Id: 3, Number: 3333N
Id: 4, Number: 4444N
Id: 5, Number: 5555N
namespace ConsoleApp;
class Program
{
public static void Main(string[] args)
{
FirstReportInvoiceDal[] firstReportInvoice =
{
new () { Id = 1, Number = "" },
new () { Id = 2, Number = "" },
new () { Id = 3, Number = "" },
new () { Id = 4, Number = "" },
new () { Id = 5, Number = "" },
};
SecondReportInvoiceDal[] secondReportInvoice =
{
new () { FirstReportId = 1, Number = "1111N" },
new () { FirstReportId = 2, Number = "2222N" },
new () { FirstReportId = 3, Number = "3333N" },
new () { FirstReportId = 4, Number = "4444N" },
new () { FirstReportId = 5, Number = "5555N" },
};
ReportRow[] rows = CreateReportRows(firstReportInvoice, secondReportInvoice);
Display(rows);
}
private static void Display(IEnumerable<ReportRow> rows)
{
foreach (ReportRow row in rows)
{
Console.WriteLine(row);
}
}
static ReportRow[] CreateReportRows(FirstReportInvoiceDal[] firstReportInvoice,
SecondReportInvoiceDal[] secondReportInvoice)
{
// Для быстрого поиска делаем словарь с ключом SecondReportInvoiceDal.FirstReportId,
// который соответствует ключу FirstReportInvoiceDal.Id.
var secondReportSet = secondReportInvoice.ToDictionary(x => x.FirstReportId);
// Для каждого firstReportInvoice сделать трансформацию (LINQ метод Select)
return firstReportInvoice.Select(x =>
{
var row = new ReportRow
{
Id = x.Id,
Number = secondReportSet[x.Id].Number
};
return row;
// Вызываем ToArray, чтобы запустилось выполнение трансформации в методе Select.
// И чтобы в принципе мы вернули данные, а не итератор.
}).ToArray();
}
}
class FirstReportInvoiceDal
{
public int Id { get; init; }
public string Number { get; init; }
}
class SecondReportInvoiceDal
{
public int FirstReportId { get; init; }
public string Number { get; init; }
}
class ReportRow
{
public int Id { get; init; }
public string Number { get; init; }
public override string ToString()
{
return $"Id: {Id}, Number: {Number}";
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
using System.Collections.ObjectModel;
using System.Globalization;
namespace VowelsCount;
public class Program
{
static void Main(string[] args)
{
var letters = new List<Letter> {
new ('а', LetterType.Vowel),
new ('б', LetterType.Consonant),
new ('в', LetterType.Consonant),
new ('г', LetterType.Consonant),
new ('д', LetterType.Consonant),
new ('е', LetterType.Vowel),
new ('ё', LetterType.Vowel),
new ('ж', LetterType.Consonant),
new ('з', LetterType.Consonant),
new ('и', LetterType.Vowel),
new ('й', LetterType.Consonant),
new ('к', LetterType.Consonant),
new ('л', LetterType.Consonant),
new ('м', LetterType.Consonant),
new ('н', LetterType.Consonant),
new ('о', LetterType.Vowel),
new ('п', LetterType.Consonant),
new ('р', LetterType.Consonant),
new ('с', LetterType.Consonant),
new ('т', LetterType.Consonant),
new ('у', LetterType.Vowel),
new ('ф', LetterType.Consonant),
new ('х', LetterType.Consonant),
new ('ц', LetterType.Consonant),
new ('ч', LetterType.Consonant),
new ('ш', LetterType.Consonant),
new ('щ', LetterType.Consonant),
new ('ъ', LetterType.Consonant),
new ('ы', LetterType.Vowel),
new ('ь', LetterType.Consonant),
new ('э', LetterType.Vowel),
new ('ю', LetterType.Vowel),
new ('я', LetterType.Vowel)
};
var alphabet = new Alphabet(letters);
IReadOnlySet<char> vowels = alphabet.GetVowelSet();
IReadOnlySet<char> consonants = alphabet.GetConsonantSet();
const string text = "Да мы хотим помочь!!!";
int vowelCounter = 0;
int consonantCounter = 0;
var vowelResult = new char[text.Length];
var consonantResult = new char[text.Length];
var otherSymbolsResult = new char[text.Length];
var ruRu = new CultureInfo("ru-RU");
for (int i = 0; i < text.Length; i++)
{
vowelResult[i] = '_';
consonantResult[i] = '_';
otherSymbolsResult[i] = '_';
char lowerCaseChar = char.ToLower(text[i], ruRu);
if (consonants.Contains(lowerCaseChar))
{
++consonantCounter;
consonantResult[i] = text[i];
}
else if (vowels.Contains(lowerCaseChar))
{
++vowelCounter;
vowelResult[i] = text[i];
}
else
{
otherSymbolsResult[i] = text[i];
}
}
Console.WriteLine("Исходная строка для подсчёта:");
Console.WriteLine(text);
Console.WriteLine("=========");
Console.WriteLine(vowelResult);
Console.WriteLine(consonantResult);
Console.WriteLine(otherSymbolsResult);
Console.WriteLine("=========");
Console.WriteLine("Кол-во символов в исходной строке: " + text.Length);
Console.WriteLine("Кол-во гласных: " + vowelCounter);
Console.WriteLine("Кол-во согласных: " + consonantCounter);
Console.WriteLine("Кол-во прочих символов: " +
(text.Length - (vowelCounter + consonantCounter)));
}
}
/// <summary>Тип буквы - гласная или согласная.</summary>
internal enum LetterType
{
/// <summary>Гласная.</summary>
Vowel,
/// <summary>Согласная.</summary>
Consonant
}
internal record struct Letter(char letter, LetterType type)
{
public LetterType Type { get; init; } = type;
public char Value { get; init; } = letter;
}
internal class Alphabet
{
public IReadOnlyList<Letter> Letters { get; }
public Alphabet(IEnumerable<Letter> letters)
{
Letters = letters switch
{
IList<Letter> list => new ReadOnlyCollection<Letter>(list),
_ => new ReadOnlyCollection<Letter>(letters.ToList()),
};
}
public IReadOnlyList<char> GetVowelList()
{
return Letters
.Where(letter => letter.Type == LetterType.Vowel)
.Select(letter => letter.Value)
.ToList()
.AsReadOnly();
}
public IReadOnlySet<char> GetVowelSet()
{
return Letters
.Where(letter => letter.Type == LetterType.Vowel)
.Select(letter => letter.Value)
.ToHashSet();
}
public IReadOnlyList<char> GetConsonantList()
{
return Letters
.Where(letter => letter.Type == LetterType.Consonant)
.Select(letter => letter.Value)
.ToList()
.AsReadOnly();
}
public IReadOnlySet<char> GetConsonantSet()
{
return Letters
.Where(letter => letter.Type == LetterType.Consonant)
.Select(letter => letter.Value)
.ToHashSet();
}
}
using System;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
int[,] arrayA = new int[3, 4]
{
{5, 5, 50, 5},
{5, 5, 5, 5},
{5, 5, 5, 2},
};
int[,] arrayB = new int[4, 2]
{
{5, 5},
{5, 1},
{15, 5},
{5, 1},
};
Console.WriteLine("Array A:");
Print(arrayA);
Console.WriteLine();
Console.WriteLine("Array B:");
Print(arrayB);
Console.WriteLine();
Console.WriteLine("Array A, first min value position:");
var (yMinA, xMinA) = FindFirstMinValuePosition(arrayA);
Print(xMinA, yMinA);
Console.WriteLine();
Console.WriteLine("Array B, first min value position:");
var (yMinB, xMinB) = FindFirstMinValuePosition(arrayB);
Print(xMinB, yMinB);
Console.WriteLine();
Console.WriteLine("Array A, first max value position:");
var (yMaxA, xMaxA) = FindFirstMaxValuePosition(arrayA);
Print(xMaxA, yMaxA);
Console.WriteLine();
Console.WriteLine("Array B, first max value position:");
var (yMaxB, xMaxB) = FindFirstMaxValuePosition(arrayB);
Print(xMaxB, yMaxB);
Swap(arrayA, arrayB, yMinA, xMinA, yMinB, xMinB);
Swap(arrayA, arrayB, yMaxA, xMaxA, yMaxB, xMaxB);
Console.WriteLine("----");
Console.WriteLine();
Console.WriteLine("Array A after two swaps:");
Print(arrayA);
Console.WriteLine();
Console.WriteLine("Array B after two swaps:");
Print(arrayB);
Console.WriteLine();
}
private static void Swap(int[,] arrayA, int[,] arrayB, int yA, int xA, int yB, int xB)
{
int tempB = arrayB[yB, xB];
arrayB[yB, xB] = arrayA[yA, xA];
arrayA[yA, xA] = tempB;
}
private static (int y, int x) FindFirstMinValuePosition(int[,] array)
{
if (array is null) throw new ArgumentNullException(nameof(array));
int y = array.GetLength(0);
int x = array.GetLength(1);
if (y == 0) throw new InvalidOperationException(
"The dimension of the array along the Y axis is zero.");
if (x == 0) throw new InvalidOperationException(
"The dimension of the array along the X axis is zero.");
int yResult = 0;
int xResult = 0;
int minValue = array[0, 0];
for (int yIndex = 0; yIndex < y; yIndex++)
{
for (int xIndex = 0; xIndex < x; xIndex++)
{
if (minValue > array[yIndex, xIndex])
{
yResult = yIndex;
xResult = xIndex;
minValue = array[yIndex, xIndex];
}
}
}
return (yResult, xResult);
}
private static (int y, int x) FindFirstMaxValuePosition(int[,] array)
{
if (array is null) throw new ArgumentNullException(nameof(array));
int y = array.GetLength(0);
int x = array.GetLength(1);
if (y == 0) throw new InvalidOperationException(
"The dimension of the array along the Y axis is zero.");
if (x == 0) throw new InvalidOperationException(
"The dimension of the array along the X axis is zero.");
int yResult = 0;
int xResult = 0;
int maxValue = array[0, 0];
for (int yIndex = 0; yIndex < y; yIndex++)
{
for (int xIndex = 0; xIndex < x; xIndex++)
{
if (maxValue < array[yIndex, xIndex])
{
yResult = yIndex;
xResult = xIndex;
maxValue = array[yIndex, xIndex];
}
}
}
return (yResult, xResult);
}
private static void Print(int x, int y)
{
Console.WriteLine($"x: {x}, y: {y}");
}
private static void Print(int[,] array)
{
int x = array.GetLength(0);
int y = array.GetLength(1);
for (int xIndex = 0; xIndex < x; xIndex++)
{
for (int yIndex = 0; yIndex < y; yIndex++)
{
Console.Write($"{array[xIndex, yIndex]}, ");
}
Console.WriteLine();
}
}
}
}
Array A:
5, 5, 50, 5,
5, 5, 5, 5,
5, 5, 5, 2,
Array B:
5, 5,
5, 1,
15, 5,
5, 1,
Array A, first min value position:
x: 3, y: 2
Array B, first min value position:
x: 1, y: 1
Array A, first max value position:
x: 2, y: 0
Array B, first max value position:
x: 0, y: 2
----
Array A after two swaps:
5, 5, 15, 5,
5, 5, 5, 5,
5, 5, 5, 1,
Array B after two swaps:
5, 5,
5, 2,
50, 5,
5, 1,
for (int i = 0; i < arraySize; i++)
{
// Используй всегда скобки. Вот опыт тебя уже научил, что без них ты получил ошибку.
}
// Program.cs
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите n");
int arraySize = int.Parse(Console.ReadLine());
int[] array = new int[arraySize];
Console.WriteLine("Введите массив А");
for (int i = 0; i < arraySize; i++)
{
array[i] = int.Parse(Console.ReadLine());
}
int max = array[0];
for (int i = 0; i < arraySize; i++)
{
if (array[i] > max)
max = array[i];
Console.Write(array[i] + " ");
}
Console.ReadLine();
}
}
// See https://aka.ms/new-console-template for more information
await DoWork();
async Task DoWork()
{
int counter = 0;
while (true)
{
Console.WriteLine($"TEST {++counter}");
await Task.Delay(900);
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
public partial class BrowserMain : Form
{
public BrowserMain()
{
InitializeComponent();
WebBrowser = new ChromiumWebBrowser(
string.IsNullOrWhiteSpace(address) ? "about:blank" : address)
{
// ...
};
Controls.Add(WebBrowser);
WebBrowser.TitleChanged += WebBrowser_TitleChanged;
WebBrowser.AddressChanged += WebBrowser_AddressChanged;
WebBrowser.LoadingStateChanged += webBrowser_DocumentCompleted;
}
private void BrowserMain_FormClosing(object sender, FormClosingEventArgs e)
{
// После вызова этих строк методы WebBrowser_TitleChanged, WebBrowser_AddressChanged
// и webBrowser_DocumentCompleted не будут выполняться.
// Это и не нужно, так как окно закрывается.
WebBrowser.TitleChanged -= WebBrowser_TitleChanged;
WebBrowser.AddressChanged -= WebBrowser_AddressChanged;
WebBrowser.LoadingStateChanged -= webBrowser_DocumentCompleted;
}
}
using System.Windows;
namespace Notification
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OnButtonClick(object sender, RoutedEventArgs e)
{
_notification.Activate();
}
}
}
using System.Windows;
using System.Windows.Controls;
namespace Notification.Controls
{
public class NotificationControl : ContentControl
{
public NotificationControl()
{
DefaultStyleKey = typeof(NotificationControl);
}
public void Activate()
{
VisualStateManager.GoToState(this, "Default", false);
VisualStateManager.GoToState(this, "Activated", true);
}
}
}
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Notification.Controls">
<KeyTime x:Key="OffsetYKeyTime">0:0:0.8</KeyTime>
<KeyTime x:Key="OpacityDelayKeyTime">0:0:1.8</KeyTime>
<KeyTime x:Key="VisibilityDelayKeyTime">0:0:2.2</KeyTime>
<Style TargetType="controls:NotificationControl">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:NotificationControl">
<Border
x:Name="RootElement"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Opacity="0"
Visibility="Collapsed">
<ContentPresenter
x:Name="ContentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<ContentPresenter.RenderTransform>
<TransformGroup>
<TranslateTransform />
<RotateTransform />
</TransformGroup>
</ContentPresenter.RenderTransform>
</ContentPresenter>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Default">
<Storyboard>
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="ContentPresenter"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)">
<EasingDoubleKeyFrame
KeyTime="0:0:0"
Value="0">
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="RootElement"
Storyboard.TargetProperty="Opacity">
<EasingDoubleKeyFrame
KeyTime="0:0:0"
Value="1">
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="RootElement"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Activated">
<Storyboard>
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="ContentPresenter"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)">
<EasingDoubleKeyFrame
KeyTime="0:0:0"
Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<QuadraticEase EasingMode="EaseOut" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame
KeyTime="{StaticResource OffsetYKeyTime}"
Value="-80">
<EasingDoubleKeyFrame.EasingFunction>
<QuadraticEase EasingMode="EaseOut" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="RootElement"
Storyboard.TargetProperty="Opacity">
<EasingDoubleKeyFrame
KeyTime="0:0:0"
Value="1">
<EasingDoubleKeyFrame.EasingFunction>
<QuadraticEase EasingMode="EaseInOut" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame
KeyTime="{StaticResource OpacityDelayKeyTime}"
Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<QuadraticEase EasingMode="EaseInOut" />
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="RootElement"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="{StaticResource VisibilityDelayKeyTime}">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
using System;
using System.Diagnostics;
using System.Reflection;
namespace ConsoleApp
{
class Program
{
private delegate ref int GetMaxNumber(ref int value1, ref int value2);
static void Main(string[] args)
{
int value1 = 5;
int value2 = 10;
var instance = new Something();
MethodInfo? methodInfo = typeof(Something).GetMethod(
nameof(Something.GetMax), BindingFlags.Public | BindingFlags.Instance);
Debug.Assert(methodInfo is not null);
var setNumber = (GetMaxNumber)Delegate.CreateDelegate(typeof(GetMaxNumber), instance, methodInfo);
setNumber.Invoke(ref value1, ref value2) = 50;
Console.WriteLine($"{nameof(value1)}: {value1}, {nameof(value2)}: {value2}");
}
}
public class Something
{
public ref int GetMax(ref int left, ref int right)
{
if (left > right)
{
return ref left;
}
return ref right;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace WinFormsApp
{
public partial class MainForm : Form
{
private readonly Timer _timer;
private int _counter;
public MainForm()
{
InitializeComponent();
_timer = new Timer();
_timer.Interval = 500;
_timer.Tick += OnTimerTick;
}
private void OnFormLoad(object sender, EventArgs e)
{
_timer.Start();
}
private void OnTimerTick(object sender, EventArgs e)
{
_label.Text = $"{nameof(OnTimerTick)}. {(++_counter).ToString()}";
}
}
}
public class Competitive
{
[JsonProperty("CurrentSeasonGamesNeededForRating")]
public int? CurrentSeasonGamesNeededForRating { get; set; }
[JsonProperty("SeasonalInfoBySeasonID")]
public object SeasonalInfoBySeasonID { get; set; }
}
<Window
x:Class="Monitor.SomeWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Monitor"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="SomeWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Window.Resources>
<Style
x:Key="BaseFontFamily"
TargetType="TextBlock">
<Setter Property="FontSize" Value="90" />
</Style>
<Style
x:Key="Numbers1Style"
BasedOn="{StaticResource BaseFontFamily}"
TargetType="TextBlock">
<Setter Property="Foreground" Value="LightCoral" />
</Style>
<Style
x:Key="Numbers2Style"
BasedOn="{StaticResource BaseFontFamily}"
TargetType="TextBlock">
<Setter Property="Foreground" Value="Bisque" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Style="{Binding TimeBlockStyle, RelativeSource={RelativeSource AncestorType=local:SomeWindow}}"
Text="{Binding Path=RightTeam.TeamCounter, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
<Button
Grid.Row="1"
Click="OnButtonClick" />
</Grid>
</Window>
public partial class SomeWindow : Window
{
public static readonly DependencyProperty TimeBlockStyleProperty = DependencyProperty.Register(
nameof(TimeBlockStyle), typeof(Style), typeof(SomeWindow), new PropertyMetadata(default(Style)));
public Style TimeBlockStyle
{
get { return (Style)GetValue(TimeBlockStyleProperty); }
set { SetValue(TimeBlockStyleProperty, value); }
}
public SomeWindow()
{
InitializeComponent();
TimeBlockStyle = (Style)Resources["Numbers1Style"];
}
private void OnButtonClick(object sender, RoutedEventArgs e)
{
TimeBlockStyle = (Style)Resources["Numbers2Style"];
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[System.Serializable]
public class TestEvent
{
[SerializeField] private int _b;
public int B => _b;
}
public class TestScript : MonoBehaviour
{
[SerializeField] private List<TestEvent> _testEvents;
private int a = 3;
void Start()
{
var events = _testEvents
.Where(item => item.B == a)
.ToArray();
}
}
public class TestScript : MonoBehaviour
{
[SerializeField] private List<TestEvent> _testEvents;
private int a = 3;
void Start()
{
var events = GetEvents(_testEvents, item => item.B == a);
}
private static List<TestEvent> GetEvents(
IEnumerable<TestEvent> testEvents, Func<TestEvent, bool> predicate)
{
var results = new List<TestEvent>();
foreach (var item in testEvents)
{
if (predicate(item))
{
results.Add(item);
}
}
return results;
}
}
public class TestScript : MonoBehaviour
{
[SerializeField] private List<TestEvent> _testEvents;
private int a = 3;
void Start()
{
var element = GetFirstOrDefault(_testEvents, item => item.B == a);
if (element is not null)
{
c = element.c;
r = element.r;
u = element.u;
}
}
// Если совпадение не найдено, то вернуть значение по умолчанию.
private static T GetFirstOrDefault<T>(IEnumerable<T> items, Func<T, bool> predicate)
{
foreach (var item in items)
{
if (predicate(item))
{
return item;
}
}
return default;
}
}