Using Generics to return a literal string or from Dictionary

前端 未结 5 1798
耶瑟儿~
耶瑟儿~ 2021-01-23 08:09

I think I outsmarted myself this time. Feel free to edit the title also I could not think of a good one.

I am reading from a file and then in that file will be a string

5条回答
  •  礼貌的吻别
    2021-01-23 08:34

    Change:

    if (typeof(T) is string)
    

    to:

    if (typeof(T) == typeof(String))
    

    The is operator is only valid on class instances. T is not actually an instance it is a type, therefor using is will not compile in your code because you need to compare 2 types. You can read more about it on msdn here.

提交回复
热议问题