zoukankan      html  css  js  c++  java
  • 封装

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 封装
    {
        class Program
        {
            static void Main(string[] args)
            {
                student s = new student();//实列化
                s.write();
    
                #region
                s.code = "101";
                s.score = 101;
                s.birthay = DateTime.Now;
    
    
    
                Console.WriteLine(s.code);
                Console.WriteLine(s.score);
                Console.WriteLine(s.birthay);
                Console.WriteLine(s.birthdaystr);
                Console.WriteLine(s.codeandscormsum);
                #endregion
    
    
    
    
                Console.ReadLine();
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 封装
    {
        class student
        {
            private string _code;//prevate 访问修饰符 并不是所有的
            //具体化
            public string code//public 访问权限最高的  所有的都可访问
            {
                get{ return _code;}
                set { _code = value;}
             }
         
            private string  _name;
            public string name { get; set; }//简写
    
    
            private decimal  _score;
            public decimal score
            {
                get { return _score; }
                set 
                {
                    if (value < 0 || value > 100)//确定取值范围
                    {
                        _score = 0;
                    }
                    else
                    {
                        _score = value;
                    }
                }
            }
            private DateTime  _birthday;
            public DateTime birthay
            {
                get { return _birthday; }
                set { _birthday = value; }
            }
    
    
            public string birthdaystr
            {
                get { return _birthday.ToString("yyyy年mm月dd日"); }
            }
    
            public string codeandscormsum
            {
                get { return _code + _score; }
            }
    
            //成员方法
            public void write()
            {
                Console.WriteLine("我是stu的write方法!");
            }
        }
    }
  • 相关阅读:
    .net事件和委托
    DataFormatString使用笔记
    DropDownList 绑定 枚举 Enum
    iOS开发如何实现消息推送机制
    JQuery调用asp.net后台方法
    Android 服务器推送技术
    Jquery Ajax ashx DataTable 传参 获取参数 C#
    jquery 基础
    [Perl书籍合集]Perl eBooks Collection
    LISP之根源
  • 原文地址:https://www.cnblogs.com/zhangdemin/p/5591421.html
Copyright © 2011-2022 走看看