printNastya
unknown
csharp
2 months ago
3.3 kB
4
Indexable
using System; // ✅ Обычный класс (class declaration) - нет `;` class MyClass { // ✅ Обычный метод (method declaration) - нет `;` void SayHello() { Console.WriteLine("Hello!"); // ✅ Выражение (expression) - нужна `;` } // ❌ Ошибка! Метод в обычном классе не может быть без тела // void DoSomething(); ❌ Ошибка CS0501 // ✅ Переменная (variable declaration) - `;` нужна int number = 10; // ✅ Метод с параметром (method with parameters) - нет `;` int Add(int a, int b) { return a + b; // ✅ Выражение (expression) - нужна `;` } } // ✅ Абстрактный класс (abstract class) - нет `;` abstract class MyAbstractClass { // ✅ Абстрактный метод (abstract method) - `;` нужна, потому что нет реализации public abstract void AbstractMethod(); // ✅ Обычный метод с телом - нет `;` public void NormalMethod() { Console.WriteLine("This is a normal method."); // ✅ `;` нужна } } // ✅ Интерфейс (interface) - нет `;` interface IMyInterface { // ✅ Метод в интерфейсе - `;` нужна, потому что нет тела void InterfaceMethod(); } // ✅ Перечисление (enum) - нет `;` enum Colors { Red, // ✅ `;` не нужна Green, Blue } class Program { // ✅ `Main` - точка входа в программу - нет `;` static void Main(string[] args) { // ✅ Выражения (statements) - `;` нужна Console.WriteLine("look at my potato"); int x = 5; // ✅ Условие (if statement) - нет `;` if (x > 0) { Console.WriteLine("x is positive"); // ✅ `;` нужна } // ❌ Ошибка! `if` нельзя ставить `;` // if (x > 0); ❌ Ошибка: пустое условие // ✅ Цикл `for` - нет `;` for (int i = 0; i < 3; i++) { Console.WriteLine(i); // ✅ `;` нужна } // ✅ Цикл `while` - нет `;` int counter = 0; while (counter < 3) { Console.WriteLine(counter); // ✅ `;` нужна counter++; } // ❌ Ошибка! `while` нельзя ставить `;` // while (counter < 3); ❌ Ошибка: пустой цикл // ✅ Лямбда-выражение (lambda expression) - `;` нужна Func<int, int, int> sum = (a, b) => a + b; Console.WriteLine(sum(5, 3)); // ✅ `;` нужна // ✅ Использование интерфейса IMyInterface myObject; // ✅ `;` нужна, объявление переменной // ✅ Использование абстрактного класса через наследника MyAbstractClass instance; // ✅ `;` нужна, объявление переменной } }
Editor is loading...
Leave a Comment