Tuesday, December 7, 2010
Declare multiple variable of same datatype easily in c#?
Do you like this story?
Recently I found this tip which helps in declaring multiple variables of the same datatype in C# using minimal code.
First I was using this code to declare the variables of type Double
double dblOpenTrades=0;
double dblDebtor=5;
double dbltotal=1789563;
double dblexcesslmt=17;
Then I found this faster way of writing the same code as below 1: double dblOpenTrades = 0, dblDebtor, dbltotal = 1789563, dblexcesslmt = 17;//
The above is applicable for all datatypes.
If you don't want to assign a value to the variable at the time of declaring use as follows 1: double dblOpenTrades = 0, dblDebtor, dbltotal = 1789563, dblexcesslmt = 17;//
Look at the variable dblDebtor in the above code there is no value assigned to it but still the code works fine.
One of the main aspects of effective programming is to make the final exe or dll as small as possible and putting less strain on the run time at the time of execution.
If you are going to start using the variables as soon as the declaration is done then this is an efficient method of declaration. But if you plan to use the variable later somewhere and in private this method of declaration is not advised.

0 Responses to “Declare multiple variable of same datatype easily in c#?”
Post a Comment