string array

  • Thread starter Thread starter Vai2000
  • Start date Start date
V

Vai2000

Hi All, How do you create a string array and initialize it with *

// Doesn't work
string [] arr=new string[7]{"*"}
// I guess this is correct, though I want a better/smart way
string [] arr=new string[7]{"*","*","*","*","*","*","*"}


TIA
 
Here is one way...in case the array bounds are a variable length...

int arrayCount = 7;
string[] myArray = new string[arrayCount];
for (int i = 0; i < 7; i++) myArray = "*";

Hope it helps :)

Mythran
 
string[] arr = GetInitializedStringArray(7);

private string[] GetInitializedStringArray(int size)
{
string[] arr = new string[size];
for( int i =0; i < size; i++)
{
arr = "*";
}
return arr;
}

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

Hi All, How do you create a string array and initialize it with *

// Doesn't work
string [] arr=new string[7]{"*"}
// I guess this is correct, though I want a better/smart way
string [] arr=new string[7]{"*","*","*","*","*","*","*"}


TIA



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
Back
Top