zoukankan      html  css  js  c++  java
  • 类的定义与使用

    using System;
    
    namespace C方法和类
    {
        class Program
        {
            public static void Main(string[] args)
            {
                //1,如果要使用一个类,就要引入它所在的命名空间,因为customer位于当前的命名空间下,所以不需要引入,可以之间使用
                Customer customer1;//在这里我们使用Customer模板,声明了一个变量(对象)
                customer1=new Customer();//对象初始化与要加new加类名
                customer1.name="siki";//我们自己定义的类声明的对象,需要初始化,才能使用
                Console.WriteLine(customer1.name);
                customer1.Show();
                //使用对象中的方法
                // TODO: Implement Functionality Here
                
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey(true);
            }
        }
    }
    //    public class Customer
        {
            //在这里我们定义了一个类
            //数据成员:里包含了4个字段
            public string name;
            public string address;
            public int age;
            public string buyTime;
            //函数成员:定义了一个方法
            public void Show(){
                Console.WriteLine("名字:"+name);
                Console.WriteLine("年龄:"+age);
                Console.WriteLine("地址:"+address);
                Console.WriteLine("购买时间:"+address);
            }
            
        }
    }

  • 相关阅读:
    webpack基本使用
    vue-路由-显示名称
    vue-父组件和路由
    vue-路由
    vue-父子组件和ref
    vue-组件
    go-面向对象编程(上)
    JavaScript的历史
    vue-列表动画
    钩子函数实现小球弹落
  • 原文地址:https://www.cnblogs.com/llhhcc/p/9879967.html
Copyright © 2011-2022 走看看