PI06 i PI06-1. Docker definitions for MSSQL and Postgres. Data seeder/generator for countries and people. Entity Framework example with variants for Postgres and MSSQL
This commit is contained in:
31
SomeOfCSharpFeatures/Inheritance/Car.cs
Normal file
31
SomeOfCSharpFeatures/Inheritance/Car.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace Inheritance;
|
||||
|
||||
public class Car : Vehicle
|
||||
{
|
||||
public int Doors { get; set; }
|
||||
public string Color { get; set; } = "White";
|
||||
|
||||
public Car(string model, double horsePower, int doors)
|
||||
: base(model, horsePower)
|
||||
{
|
||||
Console.WriteLine($"Creating car {model}");
|
||||
this.Doors = doors;
|
||||
}
|
||||
|
||||
public void BuckleSeatBelt()
|
||||
{
|
||||
Console.WriteLine("Car {0} - seat belt buckled", Model);
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
Console.WriteLine("Start Car " + Model);
|
||||
}
|
||||
|
||||
public new void Stop()
|
||||
{
|
||||
Console.WriteLine("Stop Car " + Model);
|
||||
}
|
||||
}
|
||||
13
SomeOfCSharpFeatures/Inheritance/ElectricCar.cs
Normal file
13
SomeOfCSharpFeatures/Inheritance/ElectricCar.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Inheritance;
|
||||
|
||||
public class ElectricCar : Car
|
||||
{
|
||||
public int BatteryCapacity { get; set; }
|
||||
public int? Range { get; set; }
|
||||
|
||||
public ElectricCar(string model, double horsePower, int doors, int batteryCapacity) :
|
||||
base(model, horsePower, doors)
|
||||
{
|
||||
this.BatteryCapacity = batteryCapacity;
|
||||
}
|
||||
}
|
||||
10
SomeOfCSharpFeatures/Inheritance/Inheritance.csproj
Normal file
10
SomeOfCSharpFeatures/Inheritance/Inheritance.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
18
SomeOfCSharpFeatures/Inheritance/Motorbike.cs
Normal file
18
SomeOfCSharpFeatures/Inheritance/Motorbike.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace Inheritance;
|
||||
|
||||
public class Motorbike : Vehicle
|
||||
{
|
||||
public bool HasSidecar { get; set; }
|
||||
public Motorbike(string model, double horsePower, bool sidecar)
|
||||
: base(model, horsePower)
|
||||
{
|
||||
Console.WriteLine($"Creating car {model}");
|
||||
this.HasSidecar = sidecar;
|
||||
}
|
||||
public override void Start()
|
||||
{
|
||||
Console.WriteLine("Start Motorbike " + Model);
|
||||
}
|
||||
}
|
||||
39
SomeOfCSharpFeatures/Inheritance/Program.cs
Normal file
39
SomeOfCSharpFeatures/Inheritance/Program.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Inheritance;
|
||||
|
||||
Vehicle v = new Vehicle("BMW Isseta", 9.5);
|
||||
v.Start();
|
||||
|
||||
Car car = new ElectricCar("Nissan Leaf", 148, 5, 40)
|
||||
{
|
||||
Range = 270
|
||||
};
|
||||
Console.WriteLine("car model = " + car.Model);
|
||||
Console.WriteLine("car horse power = " + car.HorsePower);
|
||||
Console.WriteLine("car number of doors = " + car.Doors);
|
||||
if (car is ElectricCar electric)
|
||||
{
|
||||
Console.WriteLine("car battery = " + electric.BatteryCapacity);
|
||||
if (electric.Range.HasValue)
|
||||
{
|
||||
Console.WriteLine("car range = " + electric.Range);
|
||||
}
|
||||
}
|
||||
|
||||
car.BuckleSeatBelt();
|
||||
car.Start();
|
||||
car.Stop();
|
||||
|
||||
((Vehicle)car).Start();
|
||||
((Vehicle)car).Stop();
|
||||
|
||||
// objekt tipa Motocikl
|
||||
Motorbike moto = new Motorbike("Ural", 41, true);
|
||||
Console.WriteLine("motorbike model {0} ", moto.Model);
|
||||
Console.WriteLine("motorbike horse power = " + moto.HorsePower);
|
||||
Console.WriteLine($"motorbike has sidecar? = {moto.HasSidecar}");
|
||||
|
||||
moto.Start();
|
||||
moto.Stop();
|
||||
|
||||
((Vehicle)moto).Start();
|
||||
((Vehicle)moto).Stop();
|
||||
26
SomeOfCSharpFeatures/Inheritance/Vehicle.cs
Normal file
26
SomeOfCSharpFeatures/Inheritance/Vehicle.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Inheritance;
|
||||
|
||||
public class Vehicle
|
||||
{
|
||||
public string Model { get; private set; }
|
||||
public double HorsePower { get; set; }
|
||||
|
||||
public Vehicle(string model, double horsePower)
|
||||
{
|
||||
Console.WriteLine("Creating vehicle " + model);
|
||||
this.Model = model;
|
||||
this.HorsePower = horsePower;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
Console.WriteLine("Stop vehicle " + Model);
|
||||
}
|
||||
|
||||
public virtual void Start()
|
||||
{
|
||||
Console.WriteLine("Start vehicle " + Model);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user