-
Aug 17th, 2017, 08:57 AM
#1
Thread Starter
Addicted Member
Debug.WriteLine syntax
I do not have much experience in Debug syntax and can't find in any book or tutorial. I am only going to present the code line for the Debug.WriteLine. The Project runs fine. My problem is to understand the Debug syntax.
1. Debug code line:
Code:
Debug.WriteLine("a1) sb1.Length = {0}, sb1.Capacity = {1}", sb1.Length,sb1.Capacity)
2. Result:
a1) sb1.Length = 3, sb1.Capacity = 16
2. What is the meaning (or roll) of:
Code:
"a1) sb1.Length = {0}, sb1.Capacity = {1}"
And of:
{0}
and
{1}
Last edited by ebellounisoft; Aug 17th, 2017 at 09:11 AM.
-
Aug 17th, 2017, 09:21 AM
#2
Re: Debug.WriteLine syntax
1) you posted in the wrong forum... I'll ask the mods to move it.
2) Did you look at the documentation?
.WriteLine uses a format string, like what String.Format uses. {0} is a place holder. It tells the formatter that the first item in the parameter array is to go into that spot. {1} Means the next item goes in that spot and so on. You can also apply other formatting to the objects depending on what they are, for example, if it is a number, you can indicate if decimals are to be displayed, how many, currency symbol, and so on.
-tg
-
Aug 17th, 2017, 09:26 AM
#3
Thread Starter
Addicted Member
Re: Debug.WriteLine syntax
The Code for the example is in language Visual Basic.NET from MSN:
https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
Thank you for your answer.
Last edited by ebellounisoft; Aug 17th, 2017 at 09:31 AM.
-
Aug 17th, 2017, 10:33 AM
#4
Re: Debug.WriteLine syntax
This isn't a special "debug syntax" but instead a more general "string formatting" syntax that many parts of the .NET framework use. I did a sort of mini-tutorial in another thread, but it wasn't focused on explaining the syntax.
Console.WriteLine(), Debug.WriteLine(), and String.Format() use a syntax MS calls "composite formatting" to help you format strings. By way of quick example, these two lines do the same thing:
Code:
Dim example As String = "Hello " & someVariable & "!"
Dim example As String = String.Format("Hello {0}!", someVariable")
To make a "format string", you type out a normal string. In places where you want to substitute a variable, you insert an {n} symbol, that is, a curly brace, a number, and a closing curly brace. The numbers should start at 0 and get bigger as the string goes on.
Any method that expects a format string also takes parameters at the end. Parameters are substituted into the string, in order, replacing the {n} symbols you made.
So if you need to put in two symbols:
Code:
Console.WriteLine("Hello, {0} {1}!", firstName, lastName)
You can also repeat them:
Code:
Console.WriteLine("Hello, {0}{1}{0}{2}", Environment.NewLine, firstName, lastName)
There are some other neat things you can do, but you can read about them in depth at your leisure.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Aug 17th, 2017, 10:38 AM
#5
Thread Starter
Addicted Member
Re: Debug.WriteLine syntax
Now I get it !!!. Thank you.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|