/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/snippets/methods/named2.cs
36 строк
1 KB
Bill Wagner
Add params collections (#40978)
21 май 2024, 00:01
Не верифицирован
21 май 2024, 00:01
57cbe8e
Код
Авторство
О чём код?
class TestMotorcycle : Motorcycle { public override int Drive(int miles, int speed) => (int)Math.Round(((double)miles) / speed, 0); public override double GetTopSpeed() => 108.4; static void Main() { var moto = new TestMotorcycle(); moto.StartEngine(); moto.AddGas(15); // <Snippet46> int travelTime = moto.Drive(170, speed: 55); // </Snippet46> Console.WriteLine("Travel time: approx. {0} hours", travelTime); } } abstract class Motorcycle { // Anyone can call this. public void StartEngine() {/* Method statements here */ } // Only derived classes can call this. protected void AddGas(int gallons) { /* Method statements here */ } // Derived classes can override the base class implementation. public virtual int Drive(int miles, int speed) { /* Method statements here */ return 1; } // Derived classes can override the base class implementation. public virtual int Drive(TimeSpan time, int speed) { /* Method statements here */ return 0; } // Derived classes must implement this. public abstract double GetTopSpeed(); }