From: nicol on 13 Jun 2010 00:26 hi i know ToString is one of methods in object class . & i use it in my program but i want to show it results when i run program(show it on screen) using System; namespace inheritance_2 { class Program { static void Main(string[] args) { point a = new point(3, 7); a.ToString(); //*********** } } } public class point { protected int x, y; public point() { } public point(int xvalue, int yvalue) { x = xvalue; y = yvalue; } public override string ToString() { //return base.ToString(); return "[" + x + "," + y + "]"; // whant to show this result } } // end class point and i want to know what is the usage of ToString thanks
From: Peter Duniho on 13 Jun 2010 00:54 nicol wrote: > hi > i know ToString is one of methods in object class . & i use it in my > program but i want to show it results when i run program(show it on > screen) All that ToString() does is provide some kind of representation of an object as a System.String object. That class doesn't do any kind of output at all by itself. If you have a console application, such as it appears in the code you posted, then you can use the System.Console class, with its Write() and WriteLine() methods to print text in the console window. If you have a GUI application, you'll have to use the API relevant to your program. For example, in a Forms application, a Label or TextBox control might be used to display the text, by setting the Text property. In WPF, a TextBlock might be what you want. It all just depends on how you want to present the text and what kind of program you're writing. Pete
From: nicol on 13 Jun 2010 01:43 On Jun 13, 8:54 am, Peter Duniho <NpOeStPe...(a)NnOwSlPiAnMk.com> wrote: > nicol wrote: > > hi > > i know ToString is one of methods in object class . & i use it in my > > program but i want to show it results when i run program(show it on > > screen) > > All that ToString() does is provide some kind of representation of an > object as a System.String object. That class doesn't do any kind of > output at all by itself. > > If you have a console application, such as it appears in the code you > posted, then you can use the System.Console class, with its Write() and > WriteLine() methods to print text in the console window. > > If you have a GUI application, you'll have to use the API relevant to > your program. For example, in a Forms application, a Label or TextBox > control might be used to display the text, by setting the Text property. > In WPF, a TextBlock might be what you want. > > It all just depends on how you want to present the text and what kind of > program you're writing. > > Pet i write in console app but i don't know how to use it in main() static void Main(string[] args) { point a = new point(3, 7); a.ToString(); //*********** } is it correct ?
From: Peter Duniho on 13 Jun 2010 01:55 nicol wrote: > i write in console app but i don't know how to use it in main() > static void Main(string[] args) > { > point a = new point(3, 7); > a.ToString(); //*********** > } > is it correct ? Microsoft has a reasonably good help system, which you can find at http://msdn.microsoft.com/. If you intend to write C# programs, you should become familiar with it. It's one thing to not understand the usage of a method like ToString(). That's fine, and a perfectly understandable issue for someone just learning the language, especially if they are also relatively new to programming. But you should be able to take a suggestion from someone, such as using the System.Console class as I suggested in my previous reply, and read about that on your own, rather than just essentially repeating the same question you asked originally. For example, given my previous suggestion, you could have entered "System.Console WriteLine" in the search for the MSDN web site, and found this page: http://msdn.microsoft.com/en-us/library/system.console.writeline.aspx That should give you plenty of information helpful in addressing the question you are asking. And now that you know about the MSDN web site, you should have a much easier time making effective use of other answers that you may receive here from time to time. :) Pete
From: Zach on 13 Jun 2010 03:05
X.ToString(); gives a string representation of X Say you have int Y = 3; Then you cannot show Y in a textbox unless you first convert Y to a string by means of Y.ToSyring(); There are things you can put inbetween the brackets. In EN-US Culture double arg = 123,456,789.00 Console.WriteLine(arg.ToString("C"));$123,456,789.00 Console.WriteLine(arg.ToString("E")); 1.234568E+008 Console.WriteLine(arg.ToString("P")); 12,345,678,900.00% Console.WriteLine(arg.ToString("N")); 123,456,789.00 Console.WriteLine(arg.ToString("F")); 123456789.00 "nicol" <nicol.young20(a)gmail.com> wrote in message news:e799ab0b-d591-4ab5-b876-dd200792b68e(a)h13g2000yqm.googlegroups.com... > hi > i know ToString is one of methods in object class . & i use it in my > program but i want to show it results when i run program(show it on > screen) > > using System; > > namespace inheritance_2 > { > class Program > { > static void Main(string[] args) > { > point a = new point(3, 7); > a.ToString(); //*********** > } > } > } > public class point > { > protected int x, y; > public point() > { > } > public point(int xvalue, int yvalue) > { > x = xvalue; > y = yvalue; > } > public override string ToString() > { > //return base.ToString(); > return "[" + x + "," + y + "]"; // whant to show this > result > } > } // end class point > > and i want to know what is the usage of ToString > thanks |