Generics
There are 4 entries for the tag
Generics
I wish generics in C# were more powerful. Why this is not legal?public class ServiceHost<TService> : ServiceHost where TService : class
{
public ServiceEndpoint AddServiceEndpoint<TServiceInterface>(Binding binding, string address)
where TService : TServiceInterface
{
return AddServiceEndpoint(typeof(TServiceInterface), binding, address);
}
}
Technorati Tags: Generics
C# doesn't stop to surprise me. While looking at Moq source code I noticed something strange: Generic constraint says class but yet somehow interfaces account for class? Technorati Tags: Moq, Generics
Can anyone tell me what am I missing here? Here's a simple class public class Mock<TType>{ private readonly TType _actual; public Mock(TType actual) { _actual = actual; } public TType Actual { get { return _actual; } } public static implicit operator TType(Mock<TType> item) { return item.Actual; }}
That's a...
Everyone knows what the new keyword is for in C# - you use it to call constructor of an object, right? What can be simpler? Actually, that's true, but not the whole truth. That's the most common way to use it. However, new is one of contextual keywords, which means, it can have different meaning, depending on the context where it's being used. The new keyword can be used in three scenarios: the one presented above, everyone immediately thinks of - creating objects. as modifier, to hide members of a base class. as generic constraint. Creating objects is pretty...