码迷,mamicode.com
首页 > 其他好文 > 详细

泛型方法

时间:2018-11-25 13:26:16      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:public   eof   方法   get   typeof   turn   泛型方法   tostring   bsp   

public T MyMethod<T, S>(T t, S s)
{
object o = t.ToString() + s.ToString();
return (T)o;
}

string s = MyMethod<string, int>("45", 56);// s=4556;

将字符串转为泛型类型

T value = (T)Convert.ChangeType(str, typeof(T));

泛型方法

标签:public   eof   方法   get   typeof   turn   泛型方法   tostring   bsp   

原文地址:https://www.cnblogs.com/bwdblogs/p/10014974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!