Using Generics to return a literal string or from Dictionary

前端 未结 5 1736
悲&欢浪女
悲&欢浪女 2021-01-27 04:51

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-27 05:04

    The line

    if (typeof(T) is string)
    

    will always return false sine the typeof operator gives a Type object. You should replace it with

    if (T is string)
    

    In addition you should look at the Convert.ChangeType method. It may be of help here.

提交回复
热议问题