Skip to content

Instantly share code, notes, and snippets.

View enisn's full-sized avatar

Enis Necipoglu enisn

View GitHub Profile
@enisn
enisn / BaseClass.cs
Created May 9, 2020 20:26
Contravariant Covariance - Sample 2
public class BaseClass
{
public int Id { get; set; }
}
public class SubClass : BaseClass
{
public string SomeData { get; set; }
}
@enisn
enisn / Program.cs
Last active July 27, 2020 09:16
Contravariance covariance - Sample 3
IDataProvider<string> a = default; // Or something else...
IDataProvider<object> b = a; // ❌Compile Error! Can't build.
@enisn
enisn / Program.cs
Last active July 27, 2020 09:17
Contravariance covariance - Sample 4
IEnumerable<string> a = default; // Or something else...
IEnumerable<object> b = a; //✅Everything is OK
@enisn
enisn / MyInterface.cs
Created May 9, 2020 20:49
Contravariance covariance - Sample 5
interface MyInterface<out T>
{
}
@enisn
enisn / MyInterface.cs
Created May 9, 2020 20:55
Contravariance covariance - Sample 6
public interface MyInterface<out T>
{
T GetData(); // ✔That's OK
void SetData(T data); // ❌This can't be used! MsBuild does'nt allow to build!
}
@enisn
enisn / IMyInterface.cs
Created May 9, 2020 20:58
Contravariance covariance - Sample 7
interface MyInterface<in T>
{
}
@enisn
enisn / MyInterface.cs
Created May 9, 2020 21:02
Contravariance covariance - Sample 8
interface MyInterface<in T>
{
T GetData(); // ❌This can't be used! MsBuild does'nt allow to build!
void SetData(T data); // ✔ Everything is OK!
}
@enisn
enisn / IDataProvider.cs
Created May 9, 2020 21:07
Contravariance covariance - Sample 9
public interface IDataProvider<out TData>
{
TData GetData();
}
@enisn
enisn / Program.cs
Last active July 27, 2020 09:17
Contravariance covariance - Sample 10
IDataProvider<string> a = default; // Or something else...
IDataProvider<object> b = a; // ✔ There is no compile error! Everything is ok 👌.
@enisn
enisn / Program.cs
Created May 16, 2020 20:58
C# - LINQ Performance 1
public static void Main(params string[] args)
{
// String dönüş tipli parametre almayan bir method:
Func<string> findName = () =>
{
return "World";
}
// String tipinde bir parametre alan değer döndürmeyen (void) bir method:
Action<string> sayHello = (name) =>