Array of String Constants?

J

Joe Cool

I am converting a VB.NET program to C#.NET.

How do I code the following from VB.NET to C#.NET?

Private DataTypes() As String = { "Text", "Integer", "Date" }

Thanks for any help!
 
A

Arne Vajhøj

Joe said:
I am converting a VB.NET program to C#.NET.

How do I code the following from VB.NET to C#.NET?

Private DataTypes() As String = { "Text", "Integer", "Date" }

private string[] DataTypes = { "Text", "Integer", "Date" };

Arne

PS: There are tools (also web based) that can convert between
C# and VB.NET !
 
D

Duy Lam

Joe said:
I am converting a VB.NET program to C#.NET.

How do I code the following from VB.NET to C#.NET?

Private DataTypes() As String = { "Text", "Integer", "Date" }

Thanks for any help!

If you want your string would be constant, add readonly keyword
private readonly string[] DataTypes = new string[] { "Text", "Integer",
"Date" };
 
J

Jon Skeet [C# MVP]

Duy Lam said:
Joe said:
I am converting a VB.NET program to C#.NET.

How do I code the following from VB.NET to C#.NET?

Private DataTypes() As String = { "Text", "Integer", "Date" }

Thanks for any help!

If you want your string would be constant, add readonly keyword
private readonly string[] DataTypes = new string[] { "Text", "Integer",
"Date" };

Unfortunately that doesn't stop the array contents from being changes.
It prevents code like this:

DataTypes = new string[5];

but it doesn't stop:

DataTypes[0] = "Image";
 

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

Top