PC Review


Reply
Thread Tools Rate Thread

Beginer Question... Quick Assigning.

 
 
NvrBst
Guest
Posts: n/a
 
      25th Aug 2006
I have a bunch of variables I'd like to assign... is it possible to do
it in 1 line.

IE This is how I do it now


int sally, jim, bill, fread, sam;
sally = jim = bill = fread = sam = 5;


Just for curosity, is there a way to do it in 1 line instead of 2?
"int sally, jim, bill, fread, sam = 5" doesn't work.

Thanks NB

 
Reply With Quote
 
 
 
 
Marcel Beutner
Guest
Posts: n/a
 
      25th Aug 2006
NvrBst wrote:
> I have a bunch of variables I'd like to assign... is it possible to do
> it in 1 line.
>
> IE This is how I do it now
>
>
> int sally, jim, bill, fread, sam;
> sally = jim = bill = fread = sam = 5;
>
>
> Just for curosity, is there a way to do it in 1 line instead of 2?
> "int sally, jim, bill, fread, sam = 5" doesn't work.
>
> Thanks NB
>


> int sally, jim, bill, fread, sam; sally = jim = bill = fread = sam = 5;


;-))
 
Reply With Quote
 
Sathyaish
Guest
Posts: n/a
 
      25th Aug 2006
You won't be able to do that multiple assignment at least until C# 3.0.
And that too only for value types.

Wait for object initializers in C# 3.0 for some quick initialization
syntax.

 
Reply With Quote
 
=?Utf-8?B?TmFuZCBLaXNob3JlIEd1cHRh?=
Guest
Posts: n/a
 
      25th Aug 2006
Sorry, there is no way to do that.

Thanks
--
Nand Kishore Gupta


"NvrBst" wrote:

> I have a bunch of variables I'd like to assign... is it possible to do
> it in 1 line.
>
> IE This is how I do it now
>
>
> int sally, jim, bill, fread, sam;
> sally = jim = bill = fread = sam = 5;
>
>
> Just for curosity, is there a way to do it in 1 line instead of 2?
> "int sally, jim, bill, fread, sam = 5" doesn't work.
>
> Thanks NB
>
>

 
Reply With Quote
 
Ben Voigt
Guest
Posts: n/a
 
      25th Aug 2006

"Nand Kishore Gupta" <(E-Mail Removed)> wrote in
message news:E47B2210-DBCB-4023-898C-(E-Mail Removed)...
> Sorry, there is no way to do that.
>
> Thanks
> --
> Nand Kishore Gupta
>
>
> "NvrBst" wrote:
>
>> I have a bunch of variables I'd like to assign... is it possible to do
>> it in 1 line.
>>
>> IE This is how I do it now
>>
>>
>> int sally, jim, bill, fread, sam;
>> sally = jim = bill = fread = sam = 5;


Your shortest option is
int sally=5, jim=5, bill=5, fred=5, sam=5;

But both should generate the same result, so why worry about saving a few
characters?

>>
>>
>> Just for curosity, is there a way to do it in 1 line instead of 2?
>> "int sally, jim, bill, fread, sam = 5" doesn't work.
>>
>> Thanks NB
>>
>>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      25th Aug 2006
That's not what the OP is asking for though. Marcel gave the correct
answer. The OP is looking for a way of assigning the same value to multiple
variables, not assign multiple values to different properties/fields on an
object.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Sathyaish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You won't be able to do that multiple assignment at least until C# 3.0.
> And that too only for value types.
>
> Wait for object initializers in C# 3.0 for some quick initialization
> syntax.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginer to UserForms question on assigning properties to objects adam_kroger@hotmail.com Microsoft Excel Misc 3 27th Jul 2007 01:45 PM
i'm beginer,i have a question about C# =?Utf-8?B?TG9ycnkgQXN0cmE=?= Microsoft C# .NET 2 26th Sep 2006 11:56 AM
Quick question - quick answer about assigning shortcut keys funkymonkUK Microsoft Excel Programming 1 13th Oct 2005 10:50 AM
Beginer question (or not?) VR Microsoft ASP .NET 3 30th Mar 2004 05:25 AM
Beginer AD Question =?Utf-8?B?Sm9obg==?= Microsoft Windows 2000 Active Directory 1 3rd Jan 2004 05:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:04 AM.