Some common usages of ToString () in C # __c#

Source: Internet
Author: User
Some common uses of ToString () in C #

Memo
Character conversion to string//C currency 2.5.ToString ("C"); ¥2.50//D 10 number 25.ToString ("D5"); 25000//E Scientific type 25000.ToString ("E"); 2.500000E+005//F fixed point 25.ToString ("F2"); 25.00//G Conventional 2.5.ToString ("G"); 2.5//N digit 2500000.ToString ("n"); 2,500,000.00//x 16 255.ToString ("X"); FF If you want 2-bit 16-digit 255.ToString ("X2");

C # date format Datetime dt = DateTime.Now;   DT. ToString ();//2005-11-5 13:21:25 dt. Tofiletime (). ToString ();//127756416859912816 dt. TOFILETIMEUTC (). ToString ();//127756704859912816 dt. ToLocalTime (). ToString ();//2005-11-5 21:21:25 dt. Tolongdatestring (). ToString ();//November 5, 2005 dt. Tolongtimestring (). ToString ();//13:21:25 dt. ToOADate (). ToString ();//38661.5565508218 dt. ToShortDateString (). ToString ();//2005-11-5 dt. Toshorttimestring (). ToString ();//13:21 dt. ToUniversalTime (). ToString ();//2005-11-5 5:21:25 dt. Year.tostring ();//2005 dt. Date.tostring ();//2005-11-5 0:00:00 dt. Dayofweek.tostring ();//saturday dt. Dayofyear.tostring ();//309 dt. Hour.tostring ();//13 dt.Millisecond.ToString ();//441 dt. Minute.tostring ();//30 dt. Month.tostring ();//11 dt. Second.tostring ();//28 dt. Ticks.tostring ();//632667942284412864 dt. Timeofday.tostring ();//13:30:28.4412864 dt. ToString ();//2005-11-5 13:47:04 dt. Addyears (1). ToString ();//2006-11-5 13:47:04 dt. AddDays (1.1). ToString ();//2005-11-6 16:11:04 dt. AddHours (1.1). ToString ();//2005-11-5 14:53:04 dt. Addmilliseconds (1.1). ToString ();//2005-11-5 13:47:04 dt. Addmonths (1). ToString ();//2005-12-5 13:47:04 dt. AddSeconds (1.1). ToString ();//2005-11-5 13:47:05 dt. AddMinutes (1.1). ToString ();//2005-11-5 13:48:10 dt. Addticks (1000). ToString ();//2005-11-5 13:47:04 dt.compareto (DT). ToString ();//0 dt. ADD (?). ToString ()//question mark is a time period dt. Equals ("2005-11-6 16:11:04"). ToString ();//false dt. Equals (DT). ToString ();//true dt. GetHashCode (). ToString ();//1474088234 dt. GetType (). ToString ();//system.datetime dt. GetTypeCode (). ToString ();//datetime    dt. Getdatetimeformats (' s ') [0]. ToString ();//2005-11-05t14:06:25 dt. Getdatetimeformats (' t ') [0]. ToString ();//14:06 dt. Getdatetimeformats (' y ') [0]. ToString ();//November 2005 dt. Getdatetimeformats (' D ') [0]. ToString ();//November 5, 2005 dt. Getdatetimeformats (' D ') [1]. ToString ();//2005 dt. Getdatetimeformats (' D ') [2]. ToString ();//week 62,005 dt. Getdatetimeformats (' D ') [3]. ToString ()//Saturday November 5, 2005 dt. Getdatetimeformats (' M ') [0]. ToString ();//November 5 dt. Getdatetimeformats (' f ') [0]. ToString ();//November 5, 2005 14:06 dt. Getdatetimeformats (' g ') [0]. ToString ();//2005-11-5 14:06 dt. Getdatetimeformats (' R ') [0]. ToString ();//sat, Nov 14:06:25 GMT   string. Format ("{0:d}", dt);//2005-11-5 string. Format ("{0:d}", dt);//November 5, 2005 string. Format ("{0:f}", dt);//November 5, 2005 14:23 string. Format ("{0:f}", dt);//November 5, 2005 14:23:23 string. Format ("{0:g}", DT);//2005-11-5 14:23 string. Format ("{0:g}", DT);//2005-11-5 14:23:23 string. Format ("{0:m}", dt);//November 5 string. Format ("{0:r}", DT);//sat, Nov 14:23:23 GMT string. Format ("{0:s}", dt);//2005-11-05t14:23:23 string. Format ("{0:t}", dt);//14:23 string. Format ("{0:t}", dt);//14:23:23 string. Format ("{0:u}", DT);//2005-11-05 14:23:23z string. Format (' {0:u} ',dt<

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.