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();
}
}
}
这个很少用,就当图个乐吧!