Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bounded array in C#... 1

Status
Not open for further replies.

netKID

Programmer
Mar 5, 2004
9
US
I am trying to learn C# and I am not able to find a way to declare a bounded string array in C#.

This is what I want, (In VB)
Dim sNames(2) as String

sNames(0)="Test1"
sNames(1)="Test2"
sNames(2)="Test3"

How do I do the same in C#?
 
Here are two solutions:
Code:
object [] sNames = new object[3];
sNames[0]="Test1";
sNames[1]="Test2";
sNames[2]="Test3";
Code:
string [] sNames2 = new String[3];
sNames2[0]="Test1";
sNames2[1]="Test2";
sNames2[2]="Test3";
Now something you have to know having the above examples:
string s = "Test";
string t = string.Copy(s);
Console.WriteLine(s == t); // returns True
Console.WriteLine((object)s == (object)t); // returns False
The reason are that because the first comparison compares two expressions of type string, and the second comparison compares two expressions of type object.
-obislavu-

 
Thanks, Sorry for the late reply, I was out of office yesterday.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top