Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking type of parameter

Tags:

c#

I would like to check, which type a parameter of a method has, in order to give the variable I determine inside the method with the wished type:

public static Object getFileContent(String filename, Type returntype)
{
     if (returntype.GetType().Equals(string))
     {
       // do something
     }
}

This doesn't work. What could I do, to check if returntype is string or List<string>?

like image 545
Luzius L Avatar asked Feb 02 '26 05:02

Luzius L


1 Answers

returntype == typeof(string)

No need to call GetType because you already have a type. (GetType would not return a useful answer anyway, it would return typeof(Type)).

like image 146
usr Avatar answered Feb 03 '26 18:02

usr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!