Commit 7d67247b authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

2020-04-28

parent b3b46733
using System;
using Microsoft.VisualBasic;
using System;
namespace _02_UebgDi_Klassse_TimeOpOverloading
{
class Time
{
int time;
public Time(int a, int b)
{
time = a * 60 + b;
}
public Time(int fromMins) { time = fromMins; }
public Time(string s)
{
string[] d = s.Split(':');
time = Convert.ToInt32(d[0]) * 60 + Convert.ToInt32(d[1]);
}
public static Time operator +(Time a, TimeSpan b)
=> new Time(a.time + b.TotalMins);
public static Time operator +(TimeSpan b, Time a)
=> new Time(a.time + b.TotalMins);
public static implicit operator Time(string s) => new Time(s);
public static TimeSpan operator -(Time t1, Time t2) => new TimeSpan(t1.time - t2.time);
public override string ToString() => $"{time / 60}:{time % 60}";
public static bool operator true(Time t) => t.time < 60 * 12;
public static bool operator false(Time t) => t.time >= 60 * 12;
public static bool operator ==(Time t1, Time t2) => t1.time == t2.time;
public static bool operator !=(Time t1, Time t2) => t1.time != t2.time;
}
class TimeSpan
{
int timeSpan;
public TimeSpan(int fromMins) { timeSpan = fromMins; }
public static implicit operator TimeSpan(string s)
{
string[] d = s.Split(':');
TimeSpan t = new TimeSpan (Convert.ToInt32( d[0]) * 60 + Convert.ToInt32( d[1]));
return t;
}
public static implicit operator TimeSpan(int x) =>new TimeSpan(x);
public int TotalMins { get => timeSpan; }
public override string ToString() => $"{timeSpan / 60}:{timeSpan % 60}";
}
class Program
{
static void Main(string[] args)
{
Time t1 = new Time(9, 45);
Time t2 = t1 + "1:30" + 15;
Time t1 = new Time("9:45");
// Klasse Time, Konstruktor(int, int)
Time t2 = 15 + t1 ; // t1.Add("1:30")
// Time.op+(Time, string) string(impl.)->TimeSpan, int(impl.)->TimeSpan | Time.op+(Time, TimeSpan)
Time t3 = "11:30";
// string(impl.)->Time
TimeSpan ts1 = t2 - t1;
// op-(Time,Time)
Console.WriteLine(t2);
// ToString
Console.WriteLine(ts1.TotalMins);
// get-Property
Console.WriteLine(ts1);
if (t2)
Console.WriteLine("Guten Morgen");
......
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"02 UebgDi Klassse TimeOpOverloading/1.0.0": {
"runtime": {
"02 UebgDi Klassse TimeOpOverloading.dll": {}
}
}
}
},
"libraries": {
"02 UebgDi Klassse TimeOpOverloading/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\wienkop\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\wienkop\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
\ No newline at end of file
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\bin\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.exe
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\bin\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.deps.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\bin\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.runtimeconfig.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\bin\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.runtimeconfig.dev.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\bin\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\bin\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\obj\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.csprojAssemblyReference.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\obj\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.csproj.CoreCompileInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\obj\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.AssemblyInfoInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\obj\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.AssemblyInfo.cs
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\obj\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\obj\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\02 UebgDi Klassse TimeOpOverloading\obj\Debug\netcoreapp3.1\02 UebgDi Klassse TimeOpOverloading.genruntimeconfig.cache
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment