Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

what does this mean?

Posted on 2008-10-10
7
Medium Priority
?
321 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 200 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
Independent Software Vendors: 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 600 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 600 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 600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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