No technical skills. If you already know it, simply ignore it.
My intention is to convert an object parameter to a generic object t to return, so the first timeCodeWrite it as follows:
Code
Public Static T getobj < T > (Employee Model)
{
T result = Default (T );
If (Model Is T)
{
Result = (T) model; // Or result = model as t;
}
Return Result;
}
However, the compiler prompts that the type cannot be converted to T, and this problem has never been encountered before. I checked the information and wrote it like this:
Code
Public Class Generictest
{
// Public static t getobj <t> (employee Model)
// {
// T result = default (t );
// If (model is T)
// {
// Result = (t) model; // Or result = model as t;
// }
// Return result;
// }
Public Static T getobj < T > (Employee Model)
{
T result = Default (T );
If (Model Is T)
{
Result = (T )( Object ) Model; // Or (t) (object) model );
}
Return Result;
}
}
The MS of the day kill.