主题:不懂结果
using System;
using System.Collections.Generic;
using System.Text;
namespace jiegoulei
{
class myclass //定义类
{
public int val;
}
struct mystruct //定义结构
{
public int val;
}
class Program
{
static void Main(string[] args)
{
myclass objectA = new myclass();
myclass objectB = objectA;
objectA.val=10;
objectB.val=20;
mystruct structA = new mystruct();
mystruct structB = structA;
structA.val=30;
structB.val=40;
Console.WriteLine("objectA.val={0}", objectA.val);
Console.WriteLine("objectB.val={0}", objectB.val);
Console.WriteLine("structA.val={0}", structA.val);
Console.WriteLine("structB.val={0}", structB.val);
Console.ReadKey();
}
}
}
结果:
objectA.val=20
objectB.val=20
structA.val=30
structB.val=40
为什么是这个情况呢.objectA.val=20为什么,不是有行代码写的objectA.val=10吗?
using System.Collections.Generic;
using System.Text;
namespace jiegoulei
{
class myclass //定义类
{
public int val;
}
struct mystruct //定义结构
{
public int val;
}
class Program
{
static void Main(string[] args)
{
myclass objectA = new myclass();
myclass objectB = objectA;
objectA.val=10;
objectB.val=20;
mystruct structA = new mystruct();
mystruct structB = structA;
structA.val=30;
structB.val=40;
Console.WriteLine("objectA.val={0}", objectA.val);
Console.WriteLine("objectB.val={0}", objectB.val);
Console.WriteLine("structA.val={0}", structA.val);
Console.WriteLine("structB.val={0}", structB.val);
Console.ReadKey();
}
}
}
结果:
objectA.val=20
objectB.val=20
structA.val=30
structB.val=40
为什么是这个情况呢.objectA.val=20为什么,不是有行代码写的objectA.val=10吗?