Constants in C #

Source: Internet
Author: User

  1. Using system;
  2. Using system. Collections. Generic;
  3. Using system. LINQ;
  4. Using system. text;
  5. Namespace CSHARP Basics
  6. {
  7. Features of class Constants
  8. {
  9. // Constants cannot be assigned with variable values. In person, the value is set to public static int age = 200;
  10. // Const int age = person. Age; Error
  11. // Define public const int age = 200 in the correct persion class;
  12. Const int age = person. Age;
  13. Public static void main ()
  14. {
  15. // Constants do not need to be declared as static. It is implicitly guaranteed that all constants are static and therefore cannot be accessed using this.
  16. // This. Age; Error
  17. // You cannot specify a value after a constant is specified.
  18. // Constant feature. Age = 22; Error
  19. }
  20. Class person
  21. {
  22. Public const int age = 200;
  23. }
  24. }
  25. }

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.