473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Beginer Question... Quick Assigning.

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

Aug 25 '06 #1
5 1185
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;
;-))
Aug 25 '06 #2
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.

Aug 25 '06 #3
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

Aug 25 '06 #4

"Nand Kishore Gupta" <Na**************@discussions.microsoft.comwrote in
message news:E4**********************************@microsof t.com...
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


Aug 25 '06 #5
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]
- mv*@spam.guard.caspershouse.com

"Sathyaish" <sa*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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.

Aug 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Gene Ellis | last post by:
Something strange is happening, but I bet it is a quick fix. My favicon image is showing up in the URL bar, for a couple of seconds, but then it disappears and the default browser icon is...
10
by: Snake | last post by:
Hello guys, I have a quick question about pointers. When I say int *p; *p = 40; cout << *p; why does that produce and error message(something about fault address)? Isnt that I created a...
1
by: ANSWER | last post by:
Is there any way I could disable user to create a new database and import all of my tables and queries into his database. I make .mde, disable shift+Enter, make logon users module (with your help...
6
by: Mike | last post by:
Lets just say my app is done HOO HOO. Now, I'm accessing the database via a web service and one thing i noticed that my app is running real slow. When I first started working on the app is ran...
3
by: Nick Stansbury | last post by:
Hi, Quick (and probably simple) question regarding shadowing and polymorphism. Problem is best explained by an example. Public Class A public CommonProperty as Integer end class Public...
6
by: Chris | last post by:
Hi all, I've recently discovered the joys of tag :) I have a ListView which is populated with strings from a List<>, and each ListView item is linked to the relevant object in List<> using Tag....
5
by: hn.ft.pris | last post by:
Hi: I'm a beginer of STL, and I'm wondering why none of below works: ######################################################################## .......... string str("string"); if ( str == "s" )...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.