2장의 주내용은 IDE가 비주얼스투디오가 코드를 우리 대신해서 만들어 주는게 아니라는 것


아주아주 기초적인 내용이라 강조할만한 건 아니지만..

왜? 너무 기본이라서 ..


그 뒤의 내용은 .net 프레임워크를 이용한 messageBox 출력 하는 방법과.. 기초적인 문법을 소개한다.


그렇지만..

중요한 정보

C#에서는 클래스 없이 프로그램이 돌아가질 않으니 반드시 클래스를 만들어줘야한다.

같은 namespace 안에 두 클래스가 있을 수 있다.


partial 키워드

-> msdn http://msdn.microsoft.com/ko-kr/library/wa80x488(v=vs.100).aspx


partial 설명은 잘 안되있어서 msdn 예제를 보고나서 이해 할 수 있었다.

public partial class CoOrds { private int x; private int y; public CoOrds(int x, int y) { this.x = x; this.y = y; } } public partial class CoOrds { public void PrintCoOrds() { Console.WriteLine("CoOrds: {0},{1}", x, y); } } class TestCoOrds { static void Main() { CoOrds myCoOrds = new CoOrds(10, 15); myCoOrds.PrintCoOrds(); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } // Output: CoOrds: 10,15



같은 이름의 클래스가 있지만 그 안의 메소드가 각각 정의 되어있고

호출 하는 쪽에서는 partial로 얼마나 나눠져있는건 신경안써도 되고 그냥 호출


사용할만한 곳 소스 파일을 동시에 작업할 때?


이것이 클래스나 인터페이스 구조체뿐만 아니고

partial 클래스 또는 구조체는 부분 메서드(Partial Method)를 포함할 수 있습니다.클래스의 한 부분에는 메서드 시그니처가 포함됩니다.같은 부분이나 다른 부분에 선택적 구현을 정의할 수 있습니다.구현을 정의하지 않으면 컴파일할 때 메서드 및 메서드에 대한 모든 호출이 제거됩니다.

도 있다.

http://msdn.microsoft.com/ko-kr/library/6b0scde8(v=vs.100).aspx


namespace PM
{
    partial class A
    {
        partial void OnSomethingHappened(string s);
    }

    // This part can be in a separate file.
    partial class A
    {
        // Comment out this method and the program
        // will still compile.
        partial void OnSomethingHappened(String s)
        {
            Console.WriteLine("Something happened: {0}", s);
        }
    }
}

partial 메소드 구현을 하려면 클래스도 당연히 partial 이 되어야 하는 것 같다.


그 외 나머지 내용은...

조건문, 변수 소개 등을 다뤄서 생략


이번 장에서 제공한 연습 ... 기초적임



namespace TestProgram000

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            string name = "Quentin";

            int x = 3;

            x = x * 17;

            double d = Math.PI / 2;

            MessageBox.Show("name is " + name + "\nx is " + x

                + "\nd is " + d);

        }


        private void button2_Click(object sender, EventArgs e)

        {

            int x = 5;

            if (x == 10)

            {

                MessageBox.Show("X must be 10");

            }

            else

            {

                MessageBox.Show("X isn't 10");

            }

        }


        private void button3_Click(object sender, EventArgs e)

        {

            int someValue = 4;

            String name = "Bobbo Jr.";

            if ((someValue == 3) && (name.Equals("Joe")))

            {

                MessageBox.Show("x is 3 and the name is Joe");


            }

            MessageBox.Show("this line runs no matter what");

        }


        private void button4_Click(object sender, EventArgs e)

        {

            int count =0;

            while(count < 10)

            {

                count = count +1;

            }

            for (int i = 0; i < 5; i++)

{

   count = count -1;

}

            MessageBox.Show("The answer is "+ count);

        }

    }

}


이 프로그램을 실행 시키면..







이렇게 나옵니다