类和对象
发布日期:2021-05-14 14:40:21 浏览次数:17 分类:精选文章

本文共 2354 字,大约阅读时间需要 7 分钟。

C#������������������������������

1. ������������

���C#������������class���������������������������������

class Student
{
public int stu_id;
public string stu_name;
public bool stu_sex;
public string stu_phone;
}

���������������

  • ������.cs������������������������������
  • ���������������������������internal������������������������public
  • 2. ���������������

    ������������������������������������������������������������������������.()���

    ������������������

    class Example
    {
    public int number = 66; // ������
    public void Output()
    {
    Console.WriteLine("number: " + number); // ������
    }
    }

    ���������������

    class Program
    {
    static void Main(string[] args)
    {
    Example ex = new Example();
    ex.number += 3;
    ex.Output();
    }
    }

    3. ������������

    ������������������������������������������������������������������������������������

    ���������

    class Student
    {
    public int stu_id;
    public string stu_name;
    public bool stu_sex;
    public string stu_phone;
    public Student()
    {
    // ���������������������������
    }
    public Student(int stu_id)
    {
    this.stu_id = stu_id;
    }
    public Student(int stu_id, string name)
    {
    this.stu_id = stu_id;
    this.stu_name = name;
    }
    }

    ���������������

    class Program
    {
    static void Main(string[] args)
    {
    Student s1 = new Student();
    Student s2 = new Student(314521);
    Student s3 = new Student(1314521, "major_s");
    }
    }

    4. ���������������Partial Classes���

    C#���������������������������������������������������������partial������������

    ���������

    public partial class MyForm
    {
    public void ButtonClicked()
    {
    Console.WriteLine("Button '{0}' is clicked", this.button);
    }
    }
    public partial class MyForm
    {
    public String button = "������";
    public void UserPressButton()
    {
    this.ButtonClicked();
    }
    }

    ���������������

    class Program
    {
    static void Main(string[] args)
    {
    MyForm form = new MyForm();
    form.button = "������";
    form.UserPressButton();
    }
    }

    ������������

  • C#���������������������������GC���������������������������������������������������������������������
  • ������������������������������������ camelCase ���������������
  • ������������������������string������������������null���������������������������������������
  • 上一篇:文件的逻辑结构
    下一篇:初识文件管理

    发表评论

    最新留言

    感谢大佬
    [***.8.128.20]2025年04月06日 07时14分07秒