Skip to content

Commit

Permalink
kharkiv alt.net meetup
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnick committed Apr 18, 2019
1 parent 5f14604 commit 8a9980a
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 108 deletions.
2 changes: 1 addition & 1 deletion ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<NullableContextOptions>enable</NullableContextOptions>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions ConsoleApp/DisposableRefStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ internal class DisposableRefStructs
public static void Showcase ()
{
using (var x = new RefStruct ())
{
WriteLine ("I pretend to use ref struct here.");
}
}

ref struct RefStruct
Expand Down
136 changes: 68 additions & 68 deletions ConsoleApp/IndicesAndRanges.cs
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
using System;
using System.Linq;
using static System.Console;

namespace ConsoleApp
{
public static class IndicesAndRanges
{
const string TearsInRain =
"I've seen things you people wouldn't believe. " + // 7
"Attack ships on fire off the shoulder of Orion. " + // 9
"I watched C-beams glitter in the dark near the Tannhäuser Gate. " + // 11
"All those moments will be lost in time, like tears in rain. " + // 12
"Time to die."; // 3

public static void Demo () => Demo1 (); // of 5

static void Demo1 ()
{
string[] words = TearsInRain.Split (' ');

WriteLine (words[3]); // you
WriteLine (words[5]); // wouldn't
WriteLine (words[41]); // die
}

static void Demo2 ()
{
string[] words = TearsInRain.Split (' ');

for (int index = 0; index < words.Length; index++)
WriteLine (words[index]);
}

static void Demo3 ()
{
string[] words =
{
"I've", "seen", "things", "you", "people", "wouldn't", "believe."
};

string[] range = words[1..3]; // play here

WriteLine (string.Join (' ', range));
}

static void Demo4 ()
{
Span<string> words = TearsInRain.Split(' ').AsSpan();

var lastWords = words[^3..];

foreach (var word in lastWords)
WriteLine (word);
}

static void Demo5 ()
{
Span<string> words = TearsInRain.Split(' ').AsSpan();

var lastWords = words[^3..];

lastWords[^1] = "live.";

foreach (var word in words)
WriteLine(word);
}
}
using System;
using System.Linq;
using static System.Console;

namespace ConsoleApp
{
public static class IndicesAndRanges
{
const string TearsInRain =
"I've seen things you people wouldn't believe. " + // 7
"Attack ships on fire off the shoulder of Orion. " + // 9
"I watched C-beams glitter in the dark near the Tannhäuser Gate. " + // 11
"All those moments will be lost in time, like tears in rain. " + // 12
"Time to die."; // 3

public static void Demo () => Demo5 (); // of 5

static void Demo3 ()
{
string[] words =
{
"I've", "seen", "things", "you", "people", "wouldn't", "believe."
};

string[] range = words[..3]; // play here

WriteLine (string.Join (' ', range));
}

static void Demo2 ()
{
string[] words = TearsInRain.Split (' ');

for (int index = 0; index < words.Length; index++)
WriteLine (words[^index]);
}

static void Demo1 ()
{
string[] words = TearsInRain.Split (' ');

WriteLine (words[3]); // you
WriteLine (words[5]); // wouldn't
WriteLine (words[^1]); // die
}

static void Demo4 ()
{
Span<string> words = TearsInRain.Split(' ').AsSpan();

Span<string> lastWords = words[^4..];

foreach (var word in lastWords)
WriteLine (word);
}

static void Demo5 ()
{
Span<string> words = TearsInRain.Split(' ').AsSpan();

var lastWords = words[^3..];

lastWords[^1] = "live.";

foreach (var word in words)
WriteLine(word);
}
}
}
11 changes: 6 additions & 5 deletions ConsoleApp/NullableReferenceTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ConsoleApp
{
internal static class NullableReferenceTypes
{
public static void Demo () => Demo1 (); // of 5
public static void Demo () => Demo5 (); // of 5

static void Demo1 ()
{
Expand All @@ -20,16 +20,17 @@ static void LogDoubleLength (string value)
int doubleLength = 2 * length;
WriteLine (doubleLength);
}

static int Length (string s) => s.Length;
static int? LengthUnsafe (string? s) => s?.Length;

static void Demo2 ()
{
LogLength ("12345");
// TODO: LogLength (null);
LogLength (null);
}

static void LogLength (string value) => WriteLine (Length (value));
static void LogLength (string? value) => WriteLine (LengthUnsafe (value));

static void Demo3 ()
{
Expand All @@ -42,7 +43,7 @@ static void Demo3 ()
static void Demo4 ()
{
Module.LogLength ("12345");
// TODO: Module.LogLength (null);
Module.LogLengthUnsafe (null);
}

static void Demo5 ()
Expand Down
32 changes: 15 additions & 17 deletions ConsoleApp/PatternMatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ enum Priority { Low, Normal, High }

internal class PatternMatching
{
public static void Demo () => Demo1 (Yesterday); // of 4
public static void Demo () => Demo4 (); // of 4

static void Demo1 (Day day)
{
var date =
day switch
{
Yesterday => DateTime.Today.AddDays (-1),
Today => DateTime.Today,
Tomorrow => DateTime.Today.AddDays (-1),
_ => throw new ArgumentOutOfRangeException (nameof(day)),
};

WriteLine (date); // TODO: refactor
}
static void Demo1 (Day day) =>
WriteLine (day switch
{
Yesterday => DateTime.Today.AddDays (-1),
Today => DateTime.Today,
Tomorrow => DateTime.Today.AddDays (-1),
_ => throw new ArgumentOutOfRangeException (nameof(day)),
});

static void Demo2 ()
{
Expand All @@ -41,7 +36,7 @@ static Priority Priority (Task task) =>
{ Price: Expensive } => High,
{ Estimate: Yesterday } => High,
{ Estimate: Tomorrow } => Low,
_ => Normal, // TODO: Bug
_ => Normal,
};

static void Demo3 () =>
Expand All @@ -66,12 +61,15 @@ static void Demo4()
static Priority Priority (Feature feature) =>
feature switch
{
(Expensive, _) => High,
(Expensive, _) => VeryHigh(),
(_, Yesterday) => High,
(_, Tomorrow) => Low,
_ => Normal, // TODO: Enhancement
Enhancement _ => Low,
(_,_) => Normal,
};

static Priority VeryHigh () => throw new Exception ("Please do this!");

class Task
{
public Task (Price price, Day estimate)
Expand Down
8 changes: 4 additions & 4 deletions ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ static void Main ()
//IndicesAndRanges.Demo ();

//DisposableRefStructs.Showcase ();
//UsingDeclarations.Showcase ();
//UsingDeclarations.Showcase();
//await AsyncStreams.Showcase ();
//StaticLocalFunctions.Showcase ();
//StaticLocalFunctions.Showcase();

//if (Now.Hour >= 20 && Now.Minute >= 30)
// Thread.Sleep (TimeSpan.FromMinutes (5));

//PatternMatching.Demo ();
//PatternMatching.Demo();

//BillionDollarMistake.Read ();
//NullableReferenceTypes.Demo ();
//ScreenToGif.Showcase ();

//Tickets.Giveaway ();

//Credits.Show ();
Credits.Show ();
}
}
}
3 changes: 2 additions & 1 deletion ConsoleApp/StaticLocalFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Linq.Enumerable;

Expand Down
4 changes: 4 additions & 0 deletions ConsoleApp/Tickets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ internal static class Tickets

public static void Giveaway ()
{
//Яков Олейник
//Сергей Руденко
//Александра Строна

WriteLine (RandomAttendee ());
WriteLine (RandomAttendee ());
WriteLine (RandomAttendee ());
Expand Down
22 changes: 10 additions & 12 deletions ConsoleApp/UsingDeclarations.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.IO;
using static System.Console;

// ReSharper disable UseUsingVarLocalVariable

namespace ConsoleApp
Expand All @@ -8,25 +10,21 @@ internal static class UsingDeclarations
{
public static void Showcase ()
{
Before ();
//After ();
//Before ();
After ();
}

static void Before ()
{
using (var stream = new MemoryStream ())
using (var writer = new StreamWriter (stream) { AutoFlush = true })
{
using (var writer = new StreamWriter (stream) { AutoFlush = true })
{
writer.Write ("Memory stream contains this.");
using (var reader = new StreamReader (stream))
WriteLine (reader.ReadToEnd ());

stream.Position = 0;
writer.Write ("Memory stream contains this.");

using (var reader = new StreamReader (stream))
{
Console.WriteLine (reader.ReadToEnd ());
}
}
stream.Position = 0;
}
}

Expand All @@ -41,7 +39,7 @@ static void After ()

using var reader = new StreamReader(stream);

Console.WriteLine(reader.ReadToEnd());
WriteLine(reader.ReadToEnd());
}
}
}

0 comments on commit 8a9980a

Please sign in to comment.