Skip to content

Instantly share code, notes, and snippets.

Dawid Sibiński iks111

Block or report user

Report or block iks111

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View DefaultInterfaceMethod_usage_NOK.cs
BackendDev dev = new BackendDev();
dev.LearnNewLanguage("Rust"); // compilation error: class 'BackendDev'
// does not contain a member 'LearnNewLanguage'
View DefaultInterfaceMethod_DiamondOfDeath.cs
interface IDeveloper
{
void LearnNewLanguage(string language)
{
Console.Write($"Learning {language} in a default way.");
}
}
interface IBackendDev : IDeveloper
{
View DefaultInterfaceMethod_usage.cs
interface IDeveloper
{
void LearnNewLanguage(string language, DateTime dueDate);
void LearnNewLanguage(string language)
{
// default implementation
LearnNewLanguage(language, DateTime.Now.AddMonths(6));
}
}
View DefaultInterfaceMethod.cs
interface IDeveloper
{
void LearnNewLanguage(string language, DateTime dueDate);
void LearnNewLanguage(string language)
{
// default implementation
LearnNewLanguage(language, DateTime.Now.AddMonths(6));
}
}
View InterfaceModified.cs
interface IDeveloper
{
void LearnNewLanguage(string language, DateTime dueDate);
void LearnNewLanguage(string language); // new method added
}
View InterfaceAndClass.cs
interface IDeveloper
{
void LearnNewLanguage(string language, DateTime dueDate);
}
class BackendDev : IDeveloper
{
public void LearnNewLanguage(string language, DateTime dueDate)
{
// Learning new language...
View CSharp8_RangeForeach.cs
var devs = new Developer[]
{
new Developer("Dawid"),
new Developer("Mark"),
new Developer("John"),
new Developer("Alice"),
new Developer("Kate")
};
foreach (var dev in devs[1..^2]) // prints "MarkJohn"
View CSharp8_RangeString.cs
var story = "C# 8 is going to be great!";
Console.WriteLine(story[^6..^0]); // prints "great!" (last 6 chars)
View RangeExpression.cs
var array = new[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
Console.WriteLine(array[2..^1]); // prints "CDEFG"
View RangeCSharp8.cs
var array = new[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
Range r = Range.Create(2, ^1); // range from 2nd to
// 1st element from the end
Console.WriteLine(array[r]); // prints "CDEFG"
You can’t perform that action at this time.