C#入门——类与对象的应用

特点:
1、类的成员结构:
1.1、数据成员:可以存储数据的空间;
1.2、方法成员:对每个数据写入/读取的方法。

2、类的调用:
2.1、类名字类型的变量声明:
类名字 变量名;(雷同整数数组声明:int[] a;)
2.2、变量空间开辟及堆中指向
变量名=new 类名字();(雷同整数数组指向:a=new int[3];)
2.3、写入数据
类名字.写入方法成员1(“abcdefg”);//字符串
类名字.写入方法成员2(22);//整数
2.4、读取数据
类名字.写入方法成员1();
类名字.写入方法成员2();

=================================
类的成员:数据成员、方法成员。

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace day0614
{
    class Wife
    {
       private string name;
       private string sex;
       private int age;

        public void  SetName(string name)
        {
            this.name = name;
        }

        public void SetAge(int age)
        {
            this.age = age;
        }

        public string GetName()
        {
            return this.name;
        }

        public int GetAge()
        {
            return this.age;
        }
    }
}

类的对象声明、写入、读取。

using System;

namespace day0614
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Wife wife01;
            wife01 = new Wife();
            wife01.SetName("hhtt");
            wife01.SetAge(22);

            Console.WriteLine("姓名:{0}\t年龄:{1}" ,wife01.GetName(),wife01.GetAge());
            Console.ReadLine();

        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值