C # often forgets knowledge

Source: Internet
Author: User

1. Const, READONLY, static
  1. The Const-Modified field representation is a constant, which is essentially compiled and the actual value of its field is written in the DLL before execution. You can change the value only when you declare it.
  2. ReadOnly is read-only and can be modified only at the time of Declaration and in the constructor. The compiled code can be seen, in fact, in the constructor to assign values in the
  3. Static, modified in one place, is valid for all objects. It uses the class name. Word by Access.
  4. The Static ReadOnly is valid and read-only for all objects. It uses the object. Word by Access. Note: Unlike ReadOnly, it is only possible to assign values at the time of declaration and in the static constructor.
2. Time string formatting

A day in the D month. One-digit date has no leading zeros.
DD a day of the month. A one-digit date has a leading zero.

M-month number. One-digit month has no leading zeros.
MM month number. One-digit month has a leading zero.

The YYYY includes the four-digit year of the era.

H 12 Hour hour system. One-digit hours do not have leading zeros.
HH 12-hour hour. One-digit hours have leading zeros.
H 24 hour hour system. One-digit hours do not have leading zeros.
HH 24-hour hour. One-digit hours have leading zeros.

M minutes. A single-digit number of minutes does not have a leading zero.
MM minutes. A single-digit number of minutes has a leading zero.

s seconds. The number of seconds in a single digit does not have a leading zero.
SS seconds. The number of seconds of one digit has a leading zero.

The fractional precision of the F-second is one digit. The remaining digits are truncated.
The fractional precision of the FF seconds is two bits. The remaining digits are truncated.

  
 
  1. String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year
  2. String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month
  3. String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day
  4. String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24
  5. String.Format("{0:m mm}", dt); // "5 05" minute
  6. String.Format("{0:s ss}", dt); // "7 07" second
  7. String.Format("{0:f ff fff ffff}", dt); // "1 12 123 1230" sec.fraction
  8. String.Format("{0:F FF FFF FFFF}", dt); // "1 12 123 123" without zeroes
  9. String.Format("{0:t tt}", dt); // "P PM" A.M. or P.M.
  10. String.Format("{0:z zz zzz}", dt); // "-6 -06 -06:00" time zone


From for notes (Wiz)

C # often forgets knowledge

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.