zoukankan      html  css  js  c++  java
  • C#--类之隐藏基类的成员

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication3
    {
       public class BaseClass
        {
            /// <summary>
            /// 常量
            /// </summary>
            public const int Number = 10;
    
            /// <summary>
            /// 属性
            /// </summary>
            public int ID { get; set; }
    
            /// <summary>
            /// 字段
            /// </summary>
            public string Name;
    
            /// <summary>
            /// 方法
            /// </summary>
            /// <returns></returns>
            public void SayHello()
            {
                Console.WriteLine("我是无返回类型的方法");
            }
    
            /// <summary>
            /// 索引
            /// </summary>
            /// <param name="index"></param>
            /// <returns></returns>
            public int this[int index]
            {
                get
                {
                    switch (index)
                    {
                        case 0:
                            return 0;
                            break;
                        case 1: return 1;
                            break;
                        case 2: return 2;
                            break;
                        case 3: return 3;
                            break;
                        default: return 10000;
                            break;
                    }
                }
                set
                {
    
                    switch (index)
                    {
                        case 0:
                            ID = value;
                            break;
                        case 1: ID = value;
                            break;
                        case 2: ID = value;
                            break;
                        case 3: ID = value;
                            break;
                        default: ID = value;
                            break;
                    }
                }
    
    
    
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication3
    {
        public class MyClass : BaseClass
        {
            /// <summary>
            /// 常量
            /// </summary>
           new public const int Number = 10;
    
            /// <summary>
            /// 属性
            /// </summary>
           new public int ID { get; set; }
    
            /// <summary>
            /// 字段
            /// </summary>
            public string Name;
    
            /// <summary>
            /// 方法
            /// </summary>
            /// <returns></returns>
            public string SayHello()
            {
                string str = "hello";
                return str;
            }
    
            /// <summary>
            /// 索引
            /// </summary>
            /// <param name="index"></param>
            /// <returns></returns>
            public int this[int index]
            {
                get
                {
                    switch (index)
                    {
                        case 0:
                            return 0;
                            break;
                        case 1: return 1;
                            break;
                        case 2: return 2;
                            break;
                        case 3: return 3;
                            break;
                        default: return 10000;
                            break;
                    }
                }
                set
                {
    
                    switch (index)
                    {
                        case 0:
                            ID = value;
                            break;
                        case 1: ID = value;
                            break;
                        case 2: ID = value;
                            break;
                        case 3: ID = value;
                            break;
                        default: ID = value;
                            break;
                    }
                }
    
    
    
            }
        }
    }

    使用new关键字隐藏基类成员

  • 相关阅读:
    使用 media 实现响应式布局
    Django组件的中间件
    Django组件的cookie和 session,用户认证组件
    Django的文件上传和分页
    Ajax
    Django模型层的多表操作(2)
    Django模型层的多表操作(1)
    Django的查询表记录
    Django2.0版本的路由层和ORM但表操作
    Django的路由层,视图层和模版层
  • 原文地址:https://www.cnblogs.com/caofangsheng/p/4859165.html
Copyright © 2011-2022 走看看