110,538
社区成员
发帖
与我相关
我的任务
分享
public class MyClass
{
private int myvalue;
public int MyValue
{
get { return myvalue; }
set { myvalue = value; }
}
public MyClass(int myvalue)
{
this.myvalue = myvalue;
}
}
public struct MyStruct
{
public int a;
public double b;
public MyClass myCls;
public int[] myArray;
}
MyStruct a = new MyStruct();
a.a = 1;
a.b = 2f;
a.myCls = new MyClass(3);
a.myArray = new int[] { 1,2,3};
MyStruct b = new MyStruct();
b = a;
b.a = 4;
b.b = 5f;
b.myCls.MyValue = 6;
b.myArray[0] = 4;
b.myArray[1] = 5;
b.myArray[2] = 6;
MessageBox.Show(a.a.ToString() + "," + a.b.ToString() + "," + a.myCls.MyValue.ToString() + "," + a.myArray[0].ToString());
MessageBox.Show(b.a.ToString() + "," + b.b.ToString() + "," + b.myCls.MyValue.ToString() + "," + b.myArray[0].ToString());
using System;
using System.Collections.Generic;
using System.Text;
namespace structdos
{
struct Ms
{
public int a;
public Ms(int b)
{
a = b;
}
}
class Program
{
static void Main(string[] args)
{
Ms first = new Ms(1);
Console.Write(first.a.ToString() + "\r\n");
Console.Read();
ChangeA(first);
}
private static void ChangeA (Ms fir)
{
Ms second=new Ms(2);
second =fir;
second.a = 3;
Console.Write(fir.a.ToString()+"\r\n");
Console.Write(second.a.ToString()+"\r\n");
Console.Read();
}
}
}