Skip to content

Instantly share code, notes, and snippets.

@mikeMoreno
mikeMoreno / misc_2.cs
Last active June 27, 2021 17:06
Medium/Is C# Getting Too Complex?/Misc 2
public Animal(string name) { Name = name; }
public Animal(string name) => Name = name;
@mikeMoreno
mikeMoreno / misc_1.cs
Last active June 27, 2021 17:06
Medium/Is C# Getting Too Complex?/Misc 1
public string GetFavoriteFood() { return favoriteFood; }
public string GetFavoriteFood() => favoriteFood;
@mikeMoreno
mikeMoreno / lists_1.cs
Last active June 27, 2021 17:06
Medium/Is C# Getting Too Complex?/Lists 1
var doubles = ints.ConvertAll(i => (double)i);
var doubles = ints.Select(i => (double)i).ToList();
@mikeMoreno
mikeMoreno / passBy_5.cs
Last active June 27, 2021 17:06
Medium/Is C# Getting Too Complex?/Pass By 5
var i = 1;
Print(i);
Console.WriteLine(i);
void Print(in int i)
{
Console.WriteLine(i);
}
@mikeMoreno
mikeMoreno / passBy_4.cs
Last active June 27, 2021 17:06
Medium/Is C# Getting Too Complex?/Pass By 4
var i = 1;
ref readonly var j = ref Print(ref i);
Console.WriteLine(i);
ref int Print(ref int i)
{
i++;
Console.WriteLine(i);
@mikeMoreno
mikeMoreno / passBy_3.cs
Last active June 27, 2021 17:06
Medium/Is C# Getting Too Complex?/Pass By 3
var i = 1;
ref var j = ref Print(ref i);
j++;
Console.WriteLine(i);
ref int Print(ref int i)
{
@mikeMoreno
mikeMoreno / objects_11.cs
Last active June 27, 2021 17:07
Medium/Is C# Getting Too Complex?/Objects 11
record Animal(string name);
@mikeMoreno
mikeMoreno / objects_10.cs
Last active June 27, 2021 17:07
Medium/Is C# Getting Too Complex?/Objects 10
record Animal
{
public string Name { get; init; }
}
@mikeMoreno
mikeMoreno / objects_9.cs
Last active June 27, 2021 17:07
Medium/Is C# Getting Too Complex?/Objects 9
struct Animal
{
public readonly string Name { get; init; }
}
struct Animal
{
public string Name { get; init; }
}
@mikeMoreno
mikeMoreno / objects_8.cs
Last active June 27, 2021 17:07
Medium/Is C# Getting Too Complex?/Objects 8
ref struct Animal
{
public string Name { get; init; }
}