20160401 C#스터디

C, C++ 2016. 4. 1. 17:20

http://www.hoons.net/lecture/list/53

http://www.csharpstudy.com/csharp/CSharp-version.aspx


# C++과 다르게 별도의 헤더파일(.h)가 없다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication1
{
    class Program
    {
        // global 변수는 0으로 초기화된다.
        int globalVar;
        const int MAX = 1024;
 
        static void Main(string[] args)
        {
            // string은 immutable 객체로 한번 할당되면 바뀌지 않는데,
            // 변수에 다른 값을 대입할 경우 새로운 메모리를 생성하여 값을 할당하고
            // 변수에 대입한다.
            string s1 = "C#";
            string s2 = "Programming";
 
            string s3 = s1 + " " + s2;
            Console.WriteLine("String; {0}", s3);
 
            string s3substring = s3.Substring(15);
        }
 
        public void localGlobal()
        {
            int localVar;
 
            // local 변수는 값을 할당하지 않으면 error 발생.
            localVar = 100;
 
            Console.WriteLine(globalVar);
            Console.WriteLine(localVar);
        }
 
        public void jaggedArray()
        {
            // 가변 배열
            // 첫번째 차원의 크기는 compile-time에 확정되어야 하고, 
            // 나머지는 동적으로 지정할 수 있다.
 
            int[][] A = new int[3][];
 
            // 배열에 새로운 배열 할당.
            A[0= new int[2];
            A[1= new int[3] { 1,2,3 };
            A[2= new int[4] { 1,2,3,4 };
 
            // 배열에 값 할당.
            A[0][0= 1;
            A[0][1= 2;
        }
    }
}
 
 
cs


: