C#基本语法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentCShrap
{
    class RectTest
    {

        public double m_length;
        private double m_width;
        private double GetArea()
        {
            return m_width * m_length;
        }

        public void AccepetDetails()
        {
            m_length = 4.5;
            m_width = 4.2; 
        }
        public void DisPlay()
        {
            Console.WriteLine("length: {0}", m_length);
            Console.WriteLine("width: {0}", m_width);
            Console.WriteLine("Area: {0}", GetArea());
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentCShrap
{
    class MainClassTest
    {
        static void Main(string[] args)
        {
            RectTest r = new RectTest();
            r.AccepetDetails();
            r.DisPlay();
            Console.WriteLine("{0}", r.m_length);
            Console.ReadKey();
            
        }
    }
}

成员变量

  1. 成员变量默认为 私有属性 ,可以强行改成公有等属性
  2. 成员变量是类的属性或者数据成员,用来存储数据的

成员函数

  1. 执行一系列指定操作的函数
  2. 类的成员函数在类内申明

标识符

  1. 标识符是用来识别类 函数 变量 或者其他用户定义的项目
  2. 标识符必须以字母下划线 或者@开头,可以在后面跟一系列字母数字下划线 @ 
  3. 标识符的第一个字符不能是数字
  4. 标识符必须不包含任何嵌入的空格或者符号 比如 ?》《*&……%¥#!
  5. 标识符不能是C#的关键字,除非在前面加上@前缀
  6. 标识符区分大小写
  7. 不能与C#的类库同名

关键字

  1. 保留关键字

    1. abstrac
    2. as
    3. base
    4. bool
    5. break
    6. byte
    7. case
    8. catch
    9. char
    10. checked
    11. class
    12. const
    13. continue
    14. decimal
    15. default
    16. delegate
    17. do
    18. double
    19. else
    20. enum
    21. event
    22. explicit
    23. extern
    24. false
    25. finally
    26. fixed
    27. float
    28. for
    29. foreach
    30. goto
    31. if
    32. implicit
    33. in
    34. int
    35. interface
    36. is
    37. lock
    38. long
    39. namespace
    40. new
    41. null
    42. operator
    43. out
    44. override
    45. params
    46. private
    47. protected
    48. public
    49. readonly
    50. ref
    51. return
    52. sbyte
    53. sealed
    54. short
    55. sizeof
    56. stackalloc
    57. static
    58. string
    59. struct
    60. switch
    61. this
    62. throw
    63. true
    64. try
    65. typeof
    66. uint
    67. ulong
    68. unchecked
    69. unsafe
    70. ushort
    71. using
    72. virtual
    73. void
    74. volatile
    75. while
  2. 上下文关键字

    1. add
    2. alias
    3. ascending
    4. descending
    5. dynamic
    6. from
    7. get
    8. global
    9. group
    10. into
    11. join
    12. let
    13. orderby
    14. partial (type)
    15. parital (method)
    16. remove
    17. select
    18. set
发布了25 篇原创文章 · 获赞 5 · 访问量 3212

猜你喜欢

转载自blog.csdn.net/Ellis1993/article/details/105258924