// 구조체 초기화 방법 데브피아 발췌..
struct test
{
public string AAA;
public string BBB;

public test(object obj)
{
this.AAA="a";
this.BBB="a";

}
}

 

구조체를 new로 생성하면 자동 초기화 된다.

 

// 구조체 배열 선언방식

[StructLayout(LayoutKind.Sequential)]

public struct Packet

{

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
byte[] aaa = new byte[2];

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
short[,] bbb= new short[2, 3];

}

 

 

struct ME
{
public char[] a ;
public short b;
public float c;
}

 

ME InitMe()

{

ME obj=new ME;

obj.a=new char[10];

obj.b=0;

obj.c=0;

return ME;

}


private void main()
{
ME ab = InitMe();


ab.b = 43;
}

 

이런식으로 하시면 되죠.. InitMe()같은걸 구조체에 넣어버리는게 클래스 객체 생성자죠.

 

+ Recent posts