Есть договор. В Европе. Можно как-то обойти?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<!-- Вот это самое главное -->
<PublishSingleFile>true</PublishSingleFile>
<!-- Это чтобы тащить за собой рантайм До .NET 6 будут рядом лежать нативные библиотеки jit-а и сборщика мусора-->
<SelfContained>true</SelfContained>
<!-- Это необходимо, чтобы сборщик понимал, для какой ОС нужен экзешник -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<!-- Это чтобы ускорить запуск -->
<PublishReadyToRun>true</PublishReadyToRun>
<!-- Эти две строки, чтобы уменьшить размер бинарника -->
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
</PropertyGroup>
</Project>
static int ReadInt(Func<int, bool> filter)
{
while (true)
{
var a = Console.ReadLine();
bool a_number = int.TryParse(a, out int ai);
if (a_number && filter(ai))
{
return ai;
}
else
{
Console.WriteLine("Некорректные данные. Попробуйте еще раз.");
}
}
}
Console.Write($"\nВведите четное значение <a>: ");
var a = ReadInt(a => a % 2 == 0);
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApp
{
class Program
{
static async Task Main(string[] args)
{
try
{
// Создаём экземпляр класса
var scanner = new Scanner();
// Вызываем асинхронный метод Scan, метод работает
// какое-то время, возвращает результат.
var data = await scanner.Scan();
foreach (var item in data)
{
// Выводим на консоль.
Console.WriteLine(item);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
public class Scanner
{
public Task<List<string>> Scan()
{
return Task.Run(async () =>
{
var results = new List<string>();
for (int i = 0; i < 10; i++)
{
// Делаем правильную задержку (имитация долгой работы для примера).
await Task.Delay(250);
// Собираем данные
results.Add(DateTimeOffset.Now.ToLocalTime().ToString());
}
return results;
});
}
public async Task<List<string>> ScanVersion2()
{
return await Task.Factory.StartNew(async () =>
{
var results = new List<string>();
for (int i = 0; i < 10; i++)
{
// Делаем правильную задержку (имитация долгой работы для примера).
await Task.Delay(250);
// Собираем данные
results.Add(DateTimeOffset.Now.ToLocalTime().ToString());
}
return results;
}, TaskCreationOptions.LongRunning)
.Unwrap() // Без этого возвращается Task<List<string>>, а не List<string>
.ConfigureAwait(false);
}
}
}
class User {
public string id;
public string name;
}
public class Program
{
public static T Request<T>(string url) where T : new() {
return new T();
}
public static void Main()
{
var user = Request<User>("https://127.0.0.1");
}
}
using System;
using UnityEngine;
using UnityEngine.UI;
public class SimpleCalculator : MonoBehaviour
{
[SerializeField] private InputField _firstInput;
[SerializeField] private InputField _secondInput;
[SerializeField] private InputField _signInput;
[SerializeField] private Text _text;
// Methods
public void Calculator()
{
int a = int.Parse(_firstInput.text);
int b = int.Parse(_secondInput.text);
_text.text = GetResult(a, b).ToString();
}
private float GetResult(int a, int b)
{
switch(_signInput.text)
{
case "+": return Add(a, b);
case "-": return Substract(a, b);
case "*": return Multiply(a, b);
case "/": return Divide(a, b);
default: throw new Exception("Invalid sign");
}
}
private float Add(int a, int b) => a + b;
private float Substract(int a, int b) => a - b;
private float Multiply(int a, int b) => a * b;
private float Divide(int a, int b) => a / b;
}