본문 바로가기
study

[C#] Chapter 03. Class (test)

by yz 2022. 5. 25.

Chap02_DataType.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyFirstCSharp_01

    // internal : 동일한 어셈블리(NameSpace) 파일 내에서만 접근이 가능하도록 하라.
{
    internal class Chap02_DataType
    {
        public string sMessage = "안녕하세요";
        public string sMessage2 = "반갑습니다";
        public string sMessage3 = "화이팅";
    }
}
 

Chap03_Class_Test.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyFirstCSharp_01
{
    public partial class Chap03_Class_Test : Form
    {
        Chap02_DataType CHP_02 = new Chap02_DataType();
        public Chap03_Class_Test()
        {
            InitializeComponent();
            Chap02_DataType CHP_02 = new Chap02_DataType();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show (CHP_02.sMessage);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show (CHP_02.sMessage2);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show (CHP_02.sMessage3);
        }
    }
}
LIST

'study' 카테고리의 다른 글

[C#] Chapter 09. if Branching Statement  (0) 2022.05.30
[C#] Chapter 08. Method Return  (0) 2022.05.30
[C#] Chapter 03. Class  (0) 2022.05.25
[C#] Chapter 02. Data Type  (0) 2022.05.25
[C#] Chapter 01. Hello World  (0) 2022.05.25