Put array values into a single variable

G

Guest

I like to put all the values of an array into a single variable like:

networkFiles = "val 1
val 2
val 3
val 4
val 5";

Here is what i am doing, but getting error message:
Operator '+' cannot be applied to operand of type 'string'

string networkFiles;
networkFiles = "";

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
localFiles = + Environment.NewLine;
}

Please help
 
G

Guest

oops.. the code should be:

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
networkFiles = + Environment.NewLine;
}
 
K

Karl Seguin

You want += not =+

and why not just use

networkFiles = String.Join("\n", localDrive);

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


huzz said:
oops.. the code should be:

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
networkFiles = + Environment.NewLine;
}


huzz said:
I like to put all the values of an array into a single variable like:

networkFiles = "val 1
val 2
val 3
val 4
val 5";

Here is what i am doing, but getting error message:
Operator '+' cannot be applied to operand of type 'string'

string networkFiles;
networkFiles = "";

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
localFiles = + Environment.NewLine;
}

Please help
 
J

Johann MacDonagh

I believe the operator should be +=, not =+. If you run into implicit
casting problems, use the ToString method that every object has.

Hope this helps,
Johann MacDonagh

huzz said:
oops.. the code should be:

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
networkFiles = + Environment.NewLine;
}


huzz said:
I like to put all the values of an array into a single variable like:

networkFiles = "val 1
val 2
val 3
val 4
val 5";

Here is what i am doing, but getting error message:
Operator '+' cannot be applied to operand of type 'string'

string networkFiles;
networkFiles = "";

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
localFiles = + Environment.NewLine;
}

Please help
 
G

Guest

perfect :), just what i neeed.

thanks karl


Karl Seguin said:
You want += not =+

and why not just use

networkFiles = String.Join("\n", localDrive);

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


huzz said:
oops.. the code should be:

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
networkFiles = + Environment.NewLine;
}


huzz said:
I like to put all the values of an array into a single variable like:

networkFiles = "val 1
val 2
val 3
val 4
val 5";

Here is what i am doing, but getting error message:
Operator '+' cannot be applied to operand of type 'string'

string networkFiles;
networkFiles = "";

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
localFiles = + Environment.NewLine;
}

Please help

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,335
Latest member
Tommiesal

Latest Threads

Top