0

hi im bigginer at c# & i have some simple questions..
1-Console.WriteLine("Result is {0}",div);
for what we use {0} here??

the bult in method Tostring() used for what & when??

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ddanbe
0

>for what we use {0} here??
It is called Format parameter. A zero-based integer that indicates which element in a list of objects to format.

Console.WriteLine("Result is {0}",div);

See format parameters.

1

1. You could see them as "placeholders"

int a = 23;
int b = 34;
Console.WriteLine("Result is {0}, second result is {1}.", a ,b );

will produce:
Result is 23, second result is 34.

2. ToString is a basic method all objects have. Because everything is C# is an object you can even do things like this:

string str = 42.ToString();

This turns the numeric litteral 42 into a string which is then assigned to the sring str. So str is now "42".
Of course you do this mostly like this:

string str = "42";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.