Using Generics to return a literal string or from Dictionary

前端 未结 5 1800
耶瑟儿~
耶瑟儿~ 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:25

    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.

提交回复
热议问题