本文共 1002 字,大约阅读时间需要 3 分钟。
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Demo{ public class ClassA { private int state = -1; public int State { get { return state; } } public class ClassB // 内部类 { public void SetPrivateState(ClassA target,int newState) { target.state = newState; } } } class Program { static void Main(string[] args) { ClassA myObject = new ClassA(); Console.WriteLine("myObject.State= {0}",myObject.State); ClassA.ClassB myOtherObject = new ClassA.ClassB(); myOtherObject.SetPrivateState(myObject,100); Console.WriteLine("myObject.State= {0}", myObject.State); Console.ReadKey(); } }}
这个很少用,就当图个乐吧!
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6763587.html,如需转载请自行联系原作者