1, Constant
const type variable name = value;
2. Enumeration
[Access control identifier] enum {Name
_ The value of 1,
_ The value of 2,
}
3, the structure
Help disposable declare multiple variables of different types
[Access control identifier] struct StructName
{
_member;
}
using System; using System.Text; namespace Demo { public struct Person { // 字段 public string _name; public int _age; public Gender _gender; } public enum Gender { male, female } class Program { static void Main() { Person p; p._name = "Linda"; p._age = 52; p._gender = Gender.female; } } }
4, method
using System; using System.Text; namespace Demo { class Program { static void Main() { Console.WriteLine(Add2(1,2)); } public static int Add2(int num1, int num2) { return num1 + num2; } } }
c#中没有全局变量,但可用静态字段进行模拟
using System; using System.Text; namespace Demo { class Program { public static int a = 10; static void Main() { Console.WriteLine(Add2()); //11 Console.WriteLine(a); //10 Console.ReadLine(); } public static int Add2() { return a + 1; } } }