I am thinking is there any way to assign different type of variables in single statement..?
string s = "";
int ia = 0;
int ib = 5;
// is there any short hand technique to assign all
// 3 variables in single statement..?:
s = ia = ib;
You can do this:
string s = "";
int ia = 0;
int ib = 5;
s = (ia = ib).ToString();
I wouldn't recommend it, but it will work - ia
will be 5, and s
will be "5".
Would you really rather do that than use two statements though? I try to avoid doing too much in a single statement - brevity is not the same thing as clarity. I think most people would find this simpler to read:
string s = "";
int ia = 0;
int ib = 5;
ia = ib;
s = ib.ToString();
Or better yet:
int ib = 5;
int ia = ib;
string s = ib.ToString();
(I dislike initializing variables with values which are just going to be overwritten without ever being read.)
See more on this question at Stackoverflow