raiden Posted December 1, 2007 Posted December 1, 2007 I am designing a calculator in C#, I need to write a code for a backspace operation. for that i need to convert the text(string) value in the calculator to a single one dimensional char array, I tried using the following string num1 = "Hello World"; char[] numarr = num1.ToCharArray(); this works only on console and does not work in forms. then I tried using arraylists, string txt1 = "Hello World"; ArrayList x1 = new ArrayList();//initializes the new arraylist x1.Add(txt1);//assigns the variable to the arraylist string txt2 = System.String.Concat(x1.ToArray()); this code crashes the app during runtime, Can anybody help me? PLEASE thanks in advance...... Quote
Administrators PlausiblyDamp Posted December 1, 2007 Administrators Posted December 1, 2007 What problems are you having with the first bit of code? If it works correctly under a console app then it certainly should work for a windows app. Not sure what the second snippet should be doing - from the look of it you should just end up with txt2 containing the same as txt1. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
raiden Posted December 1, 2007 Author Posted December 1, 2007 (edited) Yes you are absolutely right, i was surprised too but wen I use it in Console app it works fine. but when I work in windows app I get the following error --------------------- Error 1 Cannot convert method group 'ToCharArray' to non-delegate type 'char[]'. Did you intend to invoke the method? D:\.NET Development\C#.NET\My C# Codes\Calculator\WindowsApplication1\Form1.cs 265 27 WindowsApplication1 --------------------- why is this happening? please help, thank you Edited December 1, 2007 by raiden Quote
Administrators PlausiblyDamp Posted December 1, 2007 Administrators Posted December 1, 2007 Could you post the actual code you are using in the windows application? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
raiden Posted December 1, 2007 Author Posted December 1, 2007 (edited) Well I think My coding is wrong Ill try to post the answer wen I correct my code, thanks anyway Edited December 2, 2007 by raiden Quote
Leaders snarfblam Posted December 3, 2007 Leaders Posted December 3, 2007 Error 1 Cannot convert method group 'ToCharArray' to non-delegate type 'char[]'. Did you intend to invoke the method? The compiler error asks an important question. Are you sure you didn't forget the parentheses in the WinForms app? Without parentheses, a function name evaluates to a method group. In case you aren't aware, or for the benefit of other programmers, a method group is a C# "type" comprised of all overloads of a method. Parentheses are required to invoke a function, even if the method has no arguments, and even if there is only one overload, in order to resolve an overload. It is a lexical matter. In other words, this error typically means you forgot your parentheses. If you forget your parentheses, you identify a method group instead of invoking a method. The compiler politely asks if you wouldn't rather invoke a method. Quote [sIGPIC]e[/sIGPIC]
raiden Posted December 3, 2007 Author Posted December 3, 2007 you are absolutely correct, my bad. I forgot about the parenthesis, anyway i solved the problem by using the following code string txt1 = "Hello"; string txt5 = ""; char[] txt2 = txt1.ToCharArray(); int abc = txt2.Length - 1; char[] txt3 = new char[abc]; for (int p = 0; p < abc; p++) { txt3[p] = txt2[p]; String txt4 = Convert.ToString(txt3[p]); txt5 = txt5 + txt4; } Console.WriteLine (txt5); [/Code] Quote
raiden Posted December 3, 2007 Author Posted December 3, 2007 I wold Like to thank all the people who helped me in this issue. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.