Solved

what does this mean?

Posted on 2008-10-10
7
314 Views
Last Modified: 2012-05-05
im new to c# and this programmer keeps using something like this in his code and i am tryinig to understand it but i have no freaking clue. maybe you call could help me with it. thank you in advance. what does @ mean and what does {2} or {3} mean and he also uses that in his query statement like select {2} .....
i don't get it at all. could you all help? thank you very much
TasksList.Text = string.Format(@"<ul class='taskslist' >

                                                 <li{0}><a href='{2}admin/default.aspx' >Administrator Tasks</a></li>

                                                 <li{1}><a href='{3}default.aspx' >Home</a></li>

Open in new window

0
Comment
Question by:StewSupport
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 12

Expert Comment

by:jazzIIIlove
ID: 22691710
This may help you:

string damn = String.Format(
    "Hello {0} {1} {2} {3} {4} {5} ",
    "I live", "in Turkey here", 3, " a.m. and tired i am", "See",'u');
Console.WriteLine(damn);

Output:
Hello I live in Turkey here 3 a.m and tired i am See u

Best regards...
0
 
LVL 5

Expert Comment

by:gemailj
ID: 22691729
@ is a overall skip all for all unique characters in the string litreal

insteat of writting "\\" you can write @"\"


0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 50 total points
ID: 22691741
As illustrated above {0} are place holders/arguments that you pass in later.  The number inside represents the order in which those parameters will be passed in since they are not named.

"Hello {0} {2} {1}" is perfectly legal and would end up saying:
Hello I live 3 in Turkey here...

Here is information on @ quoting strings and its advantage:
http://msdn.microsoft.com/en-us/library/362314fe(VS.71).aspx
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Accepted Solution

by:
gemailj earned 150 total points
ID: 22691742
the numbers between braces like {0} {1} is used for formatting strings
like putting strings inside another string

string firstname = "john";

string lastname = "emil";

Console.Write("first name : {0}, last name : {1}", firstname , lastname);

Open in new window

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22691743
What gemailj said.  I didn't see that post as I was typing myself, but that is the purpose for @-quoted string as you will see in my link to MSDN.
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 150 total points
ID: 22691749
the prograammer is using placeholders in {0} and {1} which can be replaced at runtine with different values so that we dont have to just use static strings but our strings are modified as required

for example
for(int i = 0; i < 10; i++
    String.Format("For Loop running for {0} time", (i+1).ToString());

read this article which puts more light on the usage of String.Format()
http://www.codeproject.com/KB/cs/StringFormat.aspx

for other kinds of formatting read the following
http://idunno.org/archive/2004/14/01/122.aspx
0
 
LVL 12

Assisted Solution

by:jazzIIIlove
jazzIIIlove earned 150 total points
ID: 22691760
Let's say i have this directory and i will use it in my code:

C:\DamnedDir\

I could either escape the back-slash characters:

string path = "C:\\DamnedDir\\"

or use a verbatim string thus:

string path = @"C:\DamnedDir\"

Usefully, strings written using the verbatim string syntax can span multiple lines, and whitespace is preserved.

P.S. verbatim = word-by-word

Best regards..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now