Solved

what does this mean?

Posted on 2008-10-10
7
315 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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