[Csharp]1 placeholder, escape character

Source: Internet
Author: User
Tags iso 8601

C # Placeholder

There is 2 ways to output multiple characters in C #.

One:

static void Main ()

{

String C=console.readline ();

String D=console.readline ();

Console.WriteLine (c+ "," +d); Use "+" as a connector

}

Both:

C # also provides another notation is a placeholder. Use {} to Represent,and fill in the number of bits occupied in {}. C # Provisions starting from 0.

Console.WriteLine ("{0},{1}", c,d);

The addition to using WriteLine () to Output,you can use the output string format.

static void Main ()

{

String C=console.readline ();

String D=console.readline ();

String M=string.format ("{0}", c);

String N=string.format ("{0}", d);

Console.WriteLine (m+ "," +n);

}

The following summarizes several common format identifier.

C or C Currency Format

D or D Decimal Format

E or E Exponent Format

F or F Fixed point Format

G or G General Format

N or n comma-separated one thousand Numbers

P or P Percentage

R or R round-trip

X or X Hex

Example

static void Main ()

{

int i=12345;

Console.WriteLine ("{0:c}", i);

Console.WriteLine ("{0:d}", i);

Console.WriteLine ("{0:e}", i);

Console.WriteLine ("{0:f}", i);

Console.WriteLine ("{0:g}", i);

Console.WriteLine ("{0:n}", i);

}

D mm/dd/yyyy Short Date pattern

D dddd,mmmm dd,yyyy Long Date pattern

F dddd,mmmm dd,yyyy hh:mm Full date and time (long date and short time)

F dddd,mmmm dd,yyyy HH:mm:ss Full Date time pattern (long date and long time)

G mm/dd/yyyy hh:mm General (short date and short time)

G mm/dd/yyyy HH:MM:SS General (short date and long time)

M,m MMMM DD Month Day pattern

R,r ddd,dd MMM yyyy,hh ': ' mm ': ' ss ' GMT ' Rfc1123pattern

S yyyy-mm-dd HH:mm:ss Sortabledatetimepattern (conforms to ISO 8601) using local time

T hh:mm short time pattern

T HH:mm:ss Long Time pattern

U yyyy-mm-dd HH:mm:ss Universal sortable-date time pattern

U dddd,mmmm dd,yyyy,hh:mm:ss Universal sortable-date time pattern

Y,y mmmm,yyyy Year Month pattern

static void Main ()    
{
          Console.WriteLine ("{0:d } ", DateTime.Now);    
           Console.WriteLine ("{0:y}", DateTime.Now);   
            Console.WriteLine ("{0:m}", DateTime.Now);    
            Console.WriteLine ("{0:t}", DateTime.Now);    
            Console.WriteLine ("{0:t}", DateTime.Now);   
            Console.WriteLine ("{0:tt}", DateTime.Now);        

}


The Escape charcter

A Special Charcter Constants

Backslash "\" at the beginning,followed by one or several characters.

A particular meaning,the meaning is different from the character of the Original,so called "Escape" character.

The main control codes used to represent those characters is not easy to use general representation.

Its roles are followed by the elimination of the original meaning of the character.



\ ' Single quotes
\ " Double quotes
\ Backslash
- Null
\a Warning
\b Backspace
\f Feed
\ Newline
\ r Enter
\ t horizontal tab
\v Vertical Tab

in C #, "C: \ \ Temp"means. The path isC: \ temp; while @ "C: \ Temp" says c: \ temp;

@' s Role is toignoretheescape character.

[Csharp]1 placeholder, escape character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.