I understand I cannot modify default(T).
How to change what default(T) returns in C#?
In my situation, we have several classes that implement functionality of the base class:
T RequestForData<T>(string request)
{
return default(T);
}
I need to modify this default functionality to handle a "Refresh" call, which I can write like this:
private DataContext _dc;
T RequestForData<T>(string request)
{
if (request == "Refresh")
{
if ((_dc != null) && !_dc.HasPendingChanges())
{
_dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
}
}
return default(T);
}
These can now be called from the MDI parent form:
foreach (var form in this.Forms)
{
form.RequestForData<bool>("Refresh");
}
As you can see from the way I have called it, RequestForData returns a Boolean value.
If I handle the call in one of my forms, I want to return TRUE, but this returns an error in Visual Studio.
Cannot implicitly convert type 'bool' to 'T'
FYI: I tried a cast, too, but the compiler says that is redundant.