方法来接受不同类型的 [英] Method to accept different types

查看:145
本文介绍了方法来接受不同类型的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能为一个方法来接受任何类型的?

Is it possible for a method to accept any type?

例如我可以这样写:

public ActionResult Edit(? vp){

}

其中,的ActionResult 将接受一个整数,浮点数,或其他任何(可能为自定义)类型?

where ActionResult would accept an Integer, float, or any other (possibly custom) type?

推荐答案

如果我明白你的意思,所以你可以使用通用这样的:

if i understand your meaning so you can use generic like that:

public ActionResult Edit<T>(T vp){ }

T重新present你想要的类型,你焕调用该方法给出的类型的&lt;?>

T represent the type you want, and whan you call the method give the type in the <>

,也可以使用对象类型如下:

or you can use object type like this:

public ActionResult Edit(object vp){ }

希望它帮助你!

这篇关于方法来接受不同类型的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆