This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
Friday, December 14, 2007
Initialize char Array in C#
If you are used to initializing a char array in C++ like the following:
But I guess let me explain the problem I'm having..
I need to pass a list of strings to a C function. And in C, in order to do that, I need a char[][]. How do I put a list of strings in C# to an array that C understands?? (C, not C++).
In C#, for example,
I can do listName[index].ToCharArray() for each string, but how do I put the entire list in a array so I can pass it to a C function?
A wormed Thanks 2 u.
ReplyDeleteIs there such thing as 2-dim char array in C#?
ReplyDeleteFor example,
char[][] name ?
If so, how do I initialize it?
I tried
char[][] name = new char[10][10];
but it didn't work.
Thanks.
(The only reason I even try to use 2-dim char array is I need to pass something to a C function.)
Yes, the syntax is a little different from C++:
ReplyDeletechar[,] name = new char[10,10];
Thank you...
ReplyDeleteBut I guess let me explain the problem I'm having..
I need to pass a list of strings to a C function. And in C, in order to do that, I need a char[][]. How do I put a list of strings in C# to an array that C understands?? (C, not C++).
In C#, for example,
I can do listName[index].ToCharArray() for each string, but how do I put the entire list in a array so I can pass it to a C function?
Please help. Thanks.
I tried this:
ReplyDeletechar[][] name = new char[][] { new char[10], new char[20]};
for (int i = 0; i < M_strListChosenColName.Count; i++)
{
name[i] = m_strListChosenColName[i].ToCharArray();
}
But when I tried to pass in "name", I got an error something about no marshaling support for nested array???
Help please!! Totally new to C#!
var mask= new[] { 'a', 'b', 'c' };
ReplyDelete