zoukankan      html  css  js  c++  java
  • C#上手练习7(方法语句2)

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

    以及静态类的使用。

    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);
            }
        }
    }

  • 相关阅读:
    BZOJ 2064: 分裂( 状压dp )
    BZOJ 2096: [Poi2010]Pilots( set )
    BZOJ 3444: 最后的晚餐( )
    BZOJ 3156: 防御准备( dp + 斜率优化 )
    BZOJ 1770: [Usaco2009 Nov]lights 燈( 高斯消元 )
    BZOJ 2466: [中山市选2009]树( 高斯消元 )
    BZOJ 1316: 树上的询问( 点分治 + 平衡树 )
    codevs 1074
    bzoj 1015
    bzoj 1798
  • 原文地址:https://www.cnblogs.com/BruceKing/p/11549926.html
Copyright © 2011-2022 走看看