MSDN vs. my compiler

Started by
3 comments, last by nagromo 19 years, 10 months ago
(C#) I am compiling my program using SharpDevelop, which uses Microsoft''s csc compiler. It gives me an error (''string'' does not contain a definition for ''Chars''(CS0117)). Here is the code: public static void Print(float x, float y, string text) { ... Gl.glCallLists(text.Length, Gl.GL_UNSIGNED_SHORT, text.Chars); //error here The MSDN docs, however, say that string.Chars is the array of characters in the string. Are the MSDN docs or Microsoft''s compiler wrong, or am I making a dumb mistake?
Advertisement
Try using strings.ToCharArray()
dumb mistake!
But seriously, you are looking at the documentation for the .NET Framework Class Library and not C#(there is a difference!). Remember that every .NET language (C#, VB.NET,C++) exposes the functionality of the underlying .NET BCL in a different way. The different ways of accessing the Chars property are given in the MSDN docs themselves. See: String.Chars Property

So, to access the Chars property in C#, you would just say text[index], where text is your string variable and index is the 0 based position of the character you want from the string.

Gl.glCallLists(text.Length, Gl.GL_UNSIGNED_SHORT, text[index]);

Also note that as per the MSDN docs, String.Chars "Gets the character at a specified character position in this instance", and not "the array of characters in the string" as you say in your post.

If you want the char array equivalent of the string, go with Yosepp's suggestion.

Hope this helped

[edited by - Tanuj on May 30, 2004 2:58:07 AM]
Oops... that was dumb. I''m now using ToCharArray, but how can I treat it as a chunk of numbers instead of as individual characters? How can I convert it to a byte[]? (That is what the function wants)

Thanks for all the help!
Look into the System.Text.Encoding.***Encoding.GetBytes() methods.

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement