zoukankan      html  css  js  c++  java
  • C# 基础·语法篇

    一、之值类型与引用类型

    public static void Main(string[] args)
            {
                int age = 10;//值类型在内存中开辟一块区域存放
                object age1 = age;//引用类型存的是地址 此时指向age的初始地址
                age += 1;//age重新开辟新的区域 此时为11,
                Console.WriteLine("fist="+age1);//指向老的区域 值为10;
                int age2=(int)age1;//引用类型转化值类型 为10;
                Console.WriteLine("test="+age2);
                age2 += 1;
                Console.WriteLine("secend="+age);
                Console.ReadKey();
            }
    

      输出结果 10 10 11

    二、之继承重写

     public class Program
        {
            public static void Main(string[] args)
            {
                Employee yee = new Employee();
                Console.ReadKey();
            }
        }
    
        class Person
        {
            protected int age = 10;
            public Person()
            {
                this.Output();
            }
            public virtual void Output()
            {
                Console.WriteLine("Person"+this.age);
            }
        }
        class Employee : Person
        {
            public Employee() : base()
            {
                base.age = 20;
            }
            public override void Output()
            {
                Console.WriteLine("Employee"+base.age);
            }
        }
    

      输出结果 10

    三、C# 关于base常见使用及基本理解

    本类代码
    public class HomeController :BaseController
        {
            [ActionTestFilter]
            public ActionResult Index()
            {
                ViewBag.Date = base.enumTest;
                return View();
            }
    }
    
    父类代码
    [ActionTestFilter]  此处使用Filter权限过滤 也可以说是面向切面编程
        public class BaseController : Controller
        {
            public EnumClass enumTest
            {
                get { return ((EnumClass)this.ViewBag.EnumClass); }
            }
        }
    
    
    this.ViewBag.EnumClass 在ActionTestFilter 里声明
     filterContext.Controller.ViewBag.EnumClass = 2;
    
    this关键字引用类的当前实例。静态成员方法中不能使用this关键字,this关键字只能在实例构造函数、实例方法或实例访问器中使用。base关键字用于从派生类中访问基类的成员
    View Code
  • 相关阅读:
    操作系统知识
    接下来 的 重点 是 运维
    并行计算 排序 是 分布式数据库 能否 突破 传统 数据库 性能 瓶颈 的 关键
    并行计算 是 趋势
    高并发 分布式 架构 的 几大 基本要素
    堆栈趣话
    虚拟机 操作系统 容器
    Lambda 表达式 是 个 好东东
    update set from 语句用法 delete 多表删除的使用 以及异常:table name "temp_new_tel" specified more than once
    我的面试
  • 原文地址:https://www.cnblogs.com/eric-gms/p/6416275.html
Copyright © 2011-2022 走看看