Put array values into a single variable

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
oops.. the code should be:

for(int i; i < localDrive.Length; i++)
{
networkFiles = + localDrive;
networkFiles = + Environment.NewLine;
}
 
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
 
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
 
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

 
Back
Top