using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 구조체TEST
{
class Program
{
struct Family
{
public int age;
public long height;
public float weight;
public Family(int a, long h, float w)
{
age = a;
height = h;
weight = w;
}
}//struct
static void Main(string[] args)
{
Family sister; //일반적인 값타입 변수선언
sister.age = 13;
sister.height = 170L;
sister.weight = 55f;
Console.WriteLine("sister : {0}-{1}-{2}", sister.age, sister.height, sister.weight);
Family brother = new Family();//디폴트생성자
Console.WriteLine("brother : {0}-{1}-{2}", brother.age, brother.height, brother.weight);
Family mother = new Family(40, 160L, 60F);//초기값을 할당할 수 있는 값타입의 구조체
Console.WriteLine("mother : {0}-{1}-{2}", mother.age, mother.height, mother.weight);
Family twins = sister;//값복사
Console.WriteLine("twins : {0}-{1}-{2}", twins.age, twins.height, twins.weight);
Console.Read();
}
}
}




최근 덧글