变量没有类型 [英] variable without type
本文介绍了变量没有类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有办法变量并稍后设置它的类型?
i意味着我们可以这样:
i wanna know if there is any way to have a variable and set it's type later ?
i mean for instance we can have this :
int s ;
但是我们可以定义像
but can we define like
variable s ;
并稍后设置其类型?
将其类型设置为int或类名?
有什么方法可以像这样的东西?
and set its type later ?
set its type as int or as a class name ?
is there any way to to something like this ?
推荐答案
你要找的是:
1. var(C#参考) [ ^ ]
2. 关于var的更多示例 [ ^ ]
What you are looking for is this:
1. var (C# Reference)[^]
2. More examples on var[^]
.Net 3及更高版本支持可用于开发的var
类型。
同样,在4.0及以上版本中,dynamic
提供类似选项。
对于var
和<$之间的差异c $ c>动态,请尝试差异化C#中的var和dynamic之间的差异[ ^ ]。
.Net 3 and above support avar
type that you can use for development.
Similarly, in 4.0 and above,dynamic
provides similar options.
For a difference betweenvar
anddynamic
, try Difference between var and dynamic in C#[^].
这篇关于变量没有类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文