0

Possible Duplicate:
C#: Assign same value to multiple variables in single statement

If I have a string declared as,

string a,b,c,d......,z;

and I want to assign all of them value "69" then what would be the best approach.

e.g.

a = b = .... = y = z = "69";

I dont want to use any array or List.

Edit

Would like to know the best approach :)

Community
  • 1
  • 1
fdgfdgs dfg
  • 669
  • 4
  • 12
  • 22
  • ooopss, sorry i wasn't knowing that – fdgfdgs dfg Aug 01 '12 at 14:40
  • What are you trying to do with this that specifically does not allow for an array? Is this homework? – ametren Aug 01 '12 at 14:40
  • Yes, it is allowed to assign the same string object to multiple variables. You can do it with a single assignment or with multiple ones. You should just get your syntax right. – Sergey Kalinichenko Aug 01 '12 at 14:40
  • LOL nope its not homework, am a developer with an year experience :L – fdgfdgs dfg Aug 01 '12 at 14:40
  • If you have a large number of variables initialized to the same value, you might be doing it wrong. Why don't you want to use an array or a list (or a Dictionary which is what I think of when I see variable names a-z) – Mark Peters Aug 01 '12 at 15:25
  • @MarkPeters I already mentioned in my question, I have requirement that I can't use Arrays or List Or Dictionary – fdgfdgs dfg Aug 02 '12 at 07:35

2 Answers2

1

try with ""

 a = b = .... = y = z = "69";

Or

int a,b,c,d......,z;
a = b = .... = y = z = 69;
Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
1

It should be a string:

a = b = .... = y = z = "69";

Or if it comes from a variable:

a = b = .... = y = z = myIntVar.ToString();
Jupaol
  • 21,107
  • 8
  • 68
  • 100