码迷,mamicode.com
首页 > Windows程序 > 详细

C#属性和readonly类型

时间:2015-04-01 00:06:26      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class AA
    {
        string s;
        public AA()
        {
            s = "123";
        }
        public string S
        {
            get {return s;}
            set { s = value; }
        }
    }
    class Program
    {
        static void change(AA t)
        {
            t.S = "000";
        }
        static void Main(string[] args)
        {
            AA t = new AA();
            Console.WriteLine(t.S);
            change(t);
            Console.WriteLine(t.S);
        }
    }
}

利用S使用户感觉就像直接访问成员变量一样,但实质上是用方法对s的操作

readonly和const类似但能在静态构造函数中赋值。

C#属性和readonly类型

标签:

原文地址:http://www.cnblogs.com/wos1239/p/4382438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!