IndexOf와 static 한정자

C#/아는것 2019. 3. 27. 15:15

IndexOf는
static 한정자를 사용하므로
인스턴스.IndexOf가 아니라
원형
class명.IndexOf로 접근해야합니다.

ex)

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

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace Study_04

{

    class ConsoleApp

    {

        public ConsoleApp()

        {

            Console.WriteLine("Hello World!");

 

            //실습 시작

            string[] arrNames = { "홍길동""임꺽정""홍상직" };

            foreach (string name in arrNames)

            {

                Console.WriteLine("{0}", name);

            }

            Console.WriteLine();

 

            for (int i = 0; i < arrNames.Length; i++)//위의 foreach와 같은 기능

            {

                Console.WriteLine("{0}", arrNames[i]);

            }

            Console.WriteLine();

 

            int j = 0;

            while (true)

            {

 

                Console.WriteLine("{0}", arrNames[j]);

                j++;

                if (j >= arrNames.Length)

                {

                    break;

                }

            }

            Console.WriteLine();

            Console.WriteLine(arrNames.GetValue(1));

            Console.WriteLine(Array.IndexOf(arrNames, "임꺽정"));

            //docs//array.GetValue()

 

        }

    }

}

 

Colored by Color Scripter

cs

'C# > 아는것' 카테고리의 다른 글

Boxing Unboxing  (0) 2019.03.28
<data type>var  (0) 2019.03.26
: