본문 바로가기
카테고리 없음

[코딩일기] C# struct(구조체)

by mania2321 2024. 7. 17.

using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using UnityEngine;

public class Helloworld_2 : MonoBehaviour
{
    // struct 구조체 ==> 다른 자료형들을 모으는 명령어

    struct HumanData
    {
        public string name;
        public float weight;
        public float height;
        public float feetSize;
    }

    void Start()
    {
        HumanData Charles = new HumanData();
        Charles.name = "철수";
        Charles.weight = 80;
        Charles.height = 180;
        Charles.feetSize = 270;

        HumanData[] players = new HumanData[5];

        // 사람 5명의 데이터를 배열로 만들 수 있음
        players[0] = new HumanData();
        players[1] = new HumanData();
        players[2] = new HumanData();
        players[3] = new HumanData();
        players[4] = new HumanData();
    }
}

댓글