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();
}
}
}
成员变量
- 成员变量默认为 私有属性 ,可以强行改成公有等属性
- 成员变量是类的属性或者数据成员,用来存储数据的
成员函数
- 执行一系列指定操作的函数
- 类的成员函数在类内申明
标识符
- 标识符是用来识别类 函数 变量 或者其他用户定义的项目
- 标识符必须以字母下划线 或者@开头,可以在后面跟一系列字母数字下划线 @
- 标识符的第一个字符不能是数字
- 标识符必须不包含任何嵌入的空格或者符号 比如 ?》《*&……%¥#!
- 标识符不能是C#的关键字,除非在前面加上@前缀
- 标识符区分大小写
- 不能与C#的类库同名
关键字
-
保留关键字
- abstrac
- as
- base
- bool
- break
- byte
- case
- catch
- char
- checked
- class
- const
- continue
- decimal
- default
- delegate
- do
- double
- else
- enum
- event
- explicit
- extern
- false
- finally
- fixed
- float
- for
- foreach
- goto
- if
- implicit
- in
- int
- interface
- is
- lock
- long
- namespace
- new
- null
- operator
- out
- override
- params
- private
- protected
- public
- readonly
- ref
- return
- sbyte
- sealed
- short
- sizeof
- stackalloc
- static
- string
- struct
- switch
- this
- throw
- true
- try
- typeof
- uint
- ulong
- unchecked
- unsafe
- ushort
- using
- virtual
- void
- volatile
- while
-
上下文关键字
- add
- alias
- ascending
- descending
- dynamic
- from
- get
- global
- group
- into
- join
- let
- orderby
- partial (type)
- parital (method)
- remove
- select
- set