设为首页 加入收藏

TOP

C#上手练习7(方法语句2)
2019-09-19 18:09:58 】 浏览:43
Tags:上手 练习 方法 语句

上一篇方法调用赋值封装,这里使用封装后调用,尽量满足开闭原则。

以及静态类的使用。

using System;

namespace KingTest03
{
    class Program
    {
        int a;
        String b;
        int c;
        static void Main(string[] args)
        {
            Program program = new Program();
            program.Book(123, "学习C#", 432);//传入实际参数
            program.print();
            Console.WriteLine("下面是静态类调用,不需要创建实例,直接使用“类名.类成员”的方式即可");
            Program1.book1(1234, "我要学习C#", 4321); //直接使用“类名.类成员”的方式
            Program1.print1(); //直接使用“类名.类成员”的方式
        }
        public void Book(int Id, String Name, int Price)//赋值也用形式参数封装起来
        {
            a = Id;
            b = Name;
            c = Price;
        }
        public void print()
        {
            Console.WriteLine("图书的编号是:" + a);
            Console.WriteLine("图书的名字是:" + b);
            Console.WriteLine("图书的价格是:" + c);
        }
    }
    public class Program1
    {
        public static int a1;
        public static String b1;
        public static int c1;
        public static void book1(int Id, String Name, int Price)
        {
            a1 = Id;
            b1 = Name;
            c1 = Price;
        }
        public static void print1()
        {
            Console.WriteLine("图书的编号是:" + a1);
            Console.WriteLine("图书的名字是:" + b1);
            Console.WriteLine("图书的价格是:" + c1);
        }
    }
}

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Winform中设置ZedGraph因设置小刻.. 下一篇Winform中设置ZedGraph的颜色填充..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目