Solved

what does this mean?

Posted on 2008-10-10
7
313 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

19 Experts available now in Live!

Get 1:1 Help Now