jeudi 25 avril 2019

Return neutral type of argument in C#

How do I return an argument's neutral form? Like the following:

object MyMethod(object a) {
    if(a is int)
        return 0;
    if(a is float)
        return 0.0;
    if(a is string)
        return "";
    if(a is char)
        return '';
    (...)
}

The default keyword doesn't seem to be of use in this case.





Aucun commentaire:

Enregistrer un commentaire