CSharp Operator Comparison - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Порівняння
Довідник C# · Практичне керівництво
Порівнює порядок числових значень і повертає bool. Для типів користувача можуть бути оголошені оператори.
Простий приклад (Example.cs)
Збережіть цей приклад окремо як Example.cs. Запускайте його незалежно від інших прикладів на сторінці.
Example.cs:
// PROJECT-EXAMPLE
int count = 3;
System.Console.WriteLine(count > 2);
Результат:
True
Синтаксис
left < right / left >= right
Приклад 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
int value = 12;
Console.WriteLine($"{value < 15}:{value > 5}:{value <= 12}:{value >= 12}");
}
}
Приклад 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
decimal balance = 12.5M, price = 8M;
Console.WriteLine(balance >= price ? "Enough" : "Missing");
}
}
Офіційне джерело: Microsoft Learn.