Click here to Skip to main content
14,937,395 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 :
C#
int s ;


but can we define like
C#
variable s ;
and set its type later ?
set its type as int or as a class name ?
is there any way to to something like this ?
Posted
Updated 14-Mar-14 21:54pm
v2

What you are looking for is this:
1. var (C# Reference)[^]
2. More examples on var[^]
   
v2
.Net 3 and above support a var type that you can use for development.
Similarly, in 4.0 and above, dynamic provides similar options.

For a difference between var and dynamic, try Difference between var and dynamic in C#[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900