Solved

what does this mean?

Posted on 2008-10-10
7
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 60

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 60

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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