Archived

This topic is now archived and is closed to further replies.

MSDN vs. my compiler

This topic is 4943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites