'.NET프로그래밍'에 해당되는 글 690건

  1. 2009.08.14 58. 클래스상속
  2. 2009.08.14 57. 네임스페이스(Namespace)
  3. 2009.08.14 56. 클래스복습
  4. 2009.08.13 33. 문자열관련함수
  5. 2009.08.13 32. 날짜관련 내장객체
  6. 2009.08.13 31. 이벤트(Event)
  7. 2009.08.13 55. 무명메서드
  8. 2009.08.13 54. 이벤트(Event)
  9. 2009.08.13 53. 대리자(Delegate)
  10. 2009.08.13 알고리즘 - 11. 병합정렬(Merge)


==> 클래스상속. cs



using System;

public class 클래스상속
{
    public static void Main(string[] args)
    {
        Child c = new Child();
        c.Hi();
    }

}



==============================================================================================



==> ParentChild.cs



using System;

public class Parent : Object //( Object는 생략가능 )
{
    private string msg = "Hi";
    protected string Message
    {
        get { return msg; }
        set { msg = value; }
    }
    public virtual void Hi()
    {
        Console.WriteLine(msg);
    }
}

public class Child : Parent // Parent클래스의 모든 기능을 Child클래스에 상속하겠다
{   
    public override void Hi()
    {
        Console.WriteLine("자식 : " + Message);
    }
}






==============================================================================================


똑같은 내용 참고자료



클래스상속.cs

 

using System;

 

public class 클래스상속

{

    static void Main(string[] args)

    {

        Child c = new Child();

        // c.msg = "메롱~";

        // 필드값 변경 가능하기 때문에 private로 변경

        // 자식 클래스에만 사용할 수 있게 하려면 protected

        c.Hi(); // 자식

       

        Console.WriteLine(c.ToString()); // Object로 부터 상속

       

    }

}

 

==============================================================================================


ParentChild.cs

 

 


using System;

 

public class Parent : Object // 모든 클래스는 Object클래스로 부터 상속 받음. 생략가능

{

    private string msg = "Hi"; // 필드는 캡슐화. 숨겨야 함

    public string Message

    {

        get { return msg; }

        set { msg = value; }

    }

    public virtual void Hi()

    {

        Console.WriteLine("Hi");

    }

}

 

public class Child : Parent

{

    //public string msg = "Hi2"; // 부모클래스에 선언되어서 따로 안해도 됨

    public override void Hi()  // new : 부모클래스의 Hi()메소드를 재정의

    {

        Console.WriteLine("자식 :" + Message);

    }

}


 

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

60. 부모의 멤버접근  (0) 2009.08.14
59. 자동차클래스상속  (0) 2009.08.14
57. 네임스페이스(Namespace)  (0) 2009.08.14
56. 클래스복습  (0) 2009.08.14
55. 무명메서드  (0) 2009.08.13
Posted by holland14
:

using System;
using hw = Hyundai.Weight; // 축약형
using Hyundai.Weight.New; // 전체

namespace 닷넷학습
{
    public class 네임스페이스
    {
        public static void Main()
        {
            System.Console.WriteLine("네임스페이스.클래스.멤버");
            Hyundai.Sonata sonata = new Hyundai.Sonata();
            sonata.Run();
            Hyundai.Weight.Genesis ge = new Hyundai.Weight.Genesis(); ge.Run();
            hw.Genesis gen = new hw.Genesis(); gen.Run();
            Equus e = new Equus(); e.Run();
        }
    }
}

namespace Hyundai
{
    public class Sonata
    {
        public void Run() { Console.WriteLine("소나타 달리다"); }
    }
    namespace Weight
    {
        public class Genesis
        {
            public void Run() { Console.WriteLine("제네시스 달리다"); }
        }
    }
    namespace Weight.New
    {
        public class Equus
        {
            public void Run() { Console.WriteLine("에쿠스 달리다"); }
        }
    }
}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

59. 자동차클래스상속  (0) 2009.08.14
58. 클래스상속  (0) 2009.08.14
56. 클래스복습  (0) 2009.08.14
55. 무명메서드  (0) 2009.08.13
54. 이벤트(Event)  (0) 2009.08.13
Posted by holland14
:


==> 클래스복습.cs


using System;
using Hyundai;

public class 클래스복습
{
    public static void Main()
    {
        Hyundai.Car car = new Car("현대");

        car.Length = 2; // 2대

        car[0] = "에쿠스";
        car[1] = "제네시스";

        car.Show(); // 에쿠스, 제네시스

        // 대리자를 통한 호출
        CarHandler ch = new CarHandler(car.Show); // ch라는 대리자인스턴스를 생성하면서, Show라는 메서드를 등록
        ch();

        car.Go += car.Show;
        car.OnGo();
    }
}



==============================================================================================


==> Car.cs


using System;
// Namespace
namespace Hyundai
{
    // Class생성
    public class Car
    {
        // Field생성
        private string name;

        // Constructor생성
        public Car()
        {
            // Empty
        }
        public Car(string name)
        {
            this.name = name;
        }

        // Property
        private int _Length;
        public int Length
        {
            get { return _Length; }
            set
            {
                _Length = value;
                names = new string[value];
            }
        }

        // Indexer 생성
        private string[] names;
        public string this[int index]
        {
            get { return names[index]; }
            set { names[index] = value; }
        }

        // Method 생성
        public void Show()
        {
            Console.WriteLine("{0}", name);
            foreach (string s in names)
            {
                Console.WriteLine("{0}", s);
            }
        }

        // Destructor 생성
        ~Car()
        {
            names = null;
        }

        // Event생성
        public event CarHandler Go; // CarHandler라는 대리자타입으로 (이벤트'Go'를)만들겠다.

        // Event Handler 생성
        public void OnGo()
        {
            if (Go != null)
            {
                Go();
            }

        }
    }
    // Delegate 생성
    public delegate void CarHandler();
 
}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

58. 클래스상속  (0) 2009.08.14
57. 네임스페이스(Namespace)  (0) 2009.08.14
55. 무명메서드  (0) 2009.08.13
54. 이벤트(Event)  (0) 2009.08.13
53. 대리자(Delegate)  (0) 2009.08.13
Posted by holland14
:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <pre>
    <script type="text/javascript">
        var s = " Abc Def Fed Cba ";
        document.writeln(s.length); // 길이
        document.writeln(s.toUpperCase()); // 대문자
        document.writeln(s.toLowerCase()); // 소문자
        document.writeln(s.bold()); // 볼드
        document.writeln(s.italics()); // 이탤릭
        document.writeln(s.charAt(1)); // 1번째 인덱스 : A, C#의 IndexOf()명령어의 역할이다.
        document.writeln(s.substr(1, 3)); // 1번째부터 3자 : C#의 Substring()과 같다.
        document.writeln(s.lastIndexOf("b")); // 뒤에서 b검색 : 14 : C#의 LastIndexOf()와 같다.
        document.writeln(s.replace("Abc", "에이비씨")); // 치환
        var arr = s.split(' '); // 공백으로 분리해서 배열에 저장
        for (var i = 0; i < arr.length; i++) {
            document.writeln(arr[i]);
        }
       
        //[!] 퀴즈 : 아래 dir변수에서 파일명과 확장자를 추출해서 출력하시오.
        var dir = "C:\\Temp\\RedPlus.gif";

        var fullname = dir.substr(dir.lastIndexOf('\\') + 1);
        var name = fullname.substr(0, fullname.lastIndexOf("."));
        var ext = fullname.substr(fullname.lastIndexOf(".") + 1);
        document.writeln("전체파일명 : " + fullname);
        document.writeln("이름 : " + name);
        document.writeln("확장자 : " + ext);
       
    </script>
    </pre>
   
</head>
<body>

</body>
</html>

Posted by holland14
:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>날짜관련내장객체</title>

    <script src="date.js" type="text/javascript"></script>
    <script src="time.js" type="text/javascript"></script>
    <script type="text/javascript">
       
        // 현재 시간을 출력
        var today = new Date();
       
        // 출력
        document.write(today.getFullYear() + "<br />");
        document.write((today.getMonth() + 1) + "<br />");
        document.write(today.getDate() + "<br />");
        document.write(today.getDay() + "<br />"); // 0요일(일) ~ 6요일(토)
        document.write(today.getHours() + "<br />");
        document.write(today.getMinutes() + "<br />");
        document.write(today.getSeconds() + "<br />");
        document.write(today.getMilliseconds() + "<br />");
       
       
        // 자바스크립트 확장
        // date.js 검색/다운로드 및 사용 ==> '날짜'관련(DateTime) 명령어
        var il = Date.getDaysInMonth(2008, 2 - 1); //
        document.write(il + "<br />");

       
        // 시간차 : TimeSpan ==> time.js 검색/ 다운로드 및 사용 ==> '시간차' 관련 명령어
        var now = Date.today();
        var birth = Date.parse("1982-02-05");
        var span = new TimeSpan(now - birth);
        document.write(span.getDays() + "일 살았습니다.");
    </script>
   
</head>
<body>

</body>
</html>

Posted by holland14
:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script type="text/javascript">
        function Go() { location.href = "http://www.naver.com/"; }
    </script>
</head>
<body onload="alert('어서오세요~');" onunload="alert('벌써 가시게???');">
    <table border="1" width="100%">
        <tr>
            <td onclick="window.alert('클릭됨');">1클릭</td>
            <td onmouseover="this.style.backgroundColor='yellow';"
                onmouseout="this.style.backgroundColor='';">2마우스오버/마우스아웃</td>
            <td ondblclick="this.style.fontWeight='bold';">3두번클릭하면볼드체</td>
        </tr>
        <tr>
            <td onmousedown="Go();">4마우스다운(마우스클릭)</td>
            <td onmousemove="alert('꽝');">5마우스무브</td>
            <td onmouseup="window.open('http://www.naver.com', '', '');">6마우스업(마우스 눌렀다 뗄 때)</td>
        </tr>
        <tr>
            <td>
                <input type="text" onkeyup="alert(this.value);" maxlength="1" />
            </td>
            <td>
                <input type="text" onkeypress="alert(this.value);" maxlength="1" />
            </td>
            <td>
                <input type="text" onkeydown="alert(this.value);" maxlength="1" />
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="포커스"
                    onfocus="this.style.border='1px solid red';"
                    onblur="this.style.border='1px dotted gray';" />
            </td>
            <td>
                <input type="text" value="1234" onchange="alert('쉬는시간~');" />
            </td>
            <td></td>
        </tr> 
    </table>
   
   
   
   
    <script>
        function GoGo(url) {
            location.href = url;
        }
    </script>
    <select onchange="GoGo(this.value);">
        <option>- 즐겨찾기 -</option>
        <option value="http://www.dotnetkorea.com/">닷넷코리아</option>
        <option value="http://www.VisualAcademy.com/">비주얼아카데미</option>
    </select>
   
    <input type="text" onselect="alert(this.value);" value="1234" />

</body>
</html>

Posted by holland14
:

using System;

namespace 무명메서드
{
    //[!] 대리자 선언
    public delegate void SayHandler(string msg);

    public class Button
    {
        public event SayHandler Click; //[1] 이벤트 생성

        public void OnClick(string msg) //[2] 이벤트 핸들러 생성
        {
            if (Click != null)
            {
                Click(msg);
            }
        }
    }

    public class Program
    {
        public static void Say(string msg)
        {
            Console.WriteLine(msg);
        }

        static void Main(string[] args)
        {
            //[1] 메서드 호출
            Program.Say("안녕"); Say("안녕");

            //[2] 대리자를 통해서 대신 호출
            SayHandler sh = new SayHandler(Program.Say);
            sh += new SayHandler(Program.Say);
            sh("방가"); // 실행

            //[3] 이벤트와 이벤트 처리기를 통해서 등록해서 호출
            Button btn = new Button();
            btn.Click += new SayHandler(Say); // 기본
            btn.Click += Say; // 축약형
            btn.OnClick("또봐");  // 실행

            //[4] 무명메서드 : 간단하게 메시지만 출력하는 기능이라면 함수사용하지 않고 그 자리에 delegate로 바꿔서 써준다.
            SayHandler hi = delegate(string msg) { Console.WriteLine(msg); };
            hi("언제"); hi("언제");
            Button button = new Button();
            button.Click += delegate(string msg) { Console.WriteLine(msg); };
            button.Click += delegate(string msg) { Console.WriteLine(msg); };
            button.OnClick("내일");

        }
    }
}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

57. 네임스페이스(Namespace)  (0) 2009.08.14
56. 클래스복습  (0) 2009.08.14
54. 이벤트(Event)  (0) 2009.08.13
53. 대리자(Delegate)  (0) 2009.08.13
알고리즘 - 11. 병합정렬(Merge)  (0) 2009.08.13
Posted by holland14
:


==> 이벤트.cs


using System;

public class 이벤트
{
    public static void Main()
    {
        //[1] 다중메서드 호출
        Hello.Hi1(); Hello.Hi2();

        //[2] 대리자 호출
        Say say;
        say = new Say(Hello.Hi1);
        say += new Say(Hello.Hi2);
        say();

        //[3] 이벤트와 핸들러로 호출
        Button btn = new Button();
        btn.Click += new Say(Hello.Hi1);
        btn.Click += new Say(Hello.Hi2);
        btn.OnClick(); // 실행

    }
}



==============================================================================================


==> Button.cs



using System;
//[!] 대리자
public delegate void Say();

public class Button
{
    //[!] 이벤트 : Click
    public event Say Click; // 형식 : 지정자 + event + 대리자이름 + 이벤트이름;
    
    //[!] 이벤트 처리기(핸들러)
    public void OnClick()
    {
        if (Click != null)
        {
            Click();
        }
    }
}

public class Hello
{
    public static void Hi1()
    {
        Console.WriteLine("안녕");
    }

    public static void Hi2()
    {
        Console.WriteLine("반가워");
    }

}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

56. 클래스복습  (0) 2009.08.14
55. 무명메서드  (0) 2009.08.13
53. 대리자(Delegate)  (0) 2009.08.13
알고리즘 - 11. 병합정렬(Merge)  (0) 2009.08.13
알고리즘 - 10. 검색(Search)  (0) 2009.08.13
Posted by holland14
:


==> 대리자.cs


using System;

public class 대리자
{
    //[!] 대리자 선언
    public delegate void GoHome(); // 매개변수가 없는 대리자
    public delegate void Gop(int a); // 매개변수가 있는 대리자
    public delegate int Hap(int a, int b); // 반환값이 있는 대리자
    public static void Main()
    {
        //[1] 다중 메서드 호출
        Car car = new Car();
       
        car.Run();
        car.Left();
        car.Right();

        //[2] 대리자를 통해서 대신 호출
        GoHome go; //[a] 대리자형 변수(개체) 선언
        go = new GoHome(car.Run); //[b] 메서드 등록
        go += new GoHome(car.Left); // Add(=car.Left 추가)
        go += new GoHome(car.Right);
        go -= new GoHome(car.Left); // Remove(=car.Left 삭제)
        go(); //[c] 대신 호출

        //[3] 매개변수가 있는 메서드 대신 호출
        Gop gop = new Gop(car.Test);
        gop(2);
        gop(4);

        //[4] 반환값 테스트
        Hap hap = new Hap(car.Sum);
        Console.WriteLine(hap(3, 5));
    }
}



/*

대리자는 클래스 밖에 선언할 수도 있다.

*/



==============================================================================================



==> Car.cs



using System;

public class Car
{
    public void Run()
    {
        Console.WriteLine("전진");
    }
    public void Left()
    {
        Console.WriteLine("좌회전");
    }
    public void Right()
    {
        Console.WriteLine("우회전");
    }

    // 매개변수가 있는 메서드
    public void Test(int a)
    {
        Console.WriteLine((a * a));
    }

    // 반환값이 있는 메서드
    public int Sum(int a, int b)
    {
        return (a + b);
    }

}
   


   

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

55. 무명메서드  (0) 2009.08.13
54. 이벤트(Event)  (0) 2009.08.13
알고리즘 - 11. 병합정렬(Merge)  (0) 2009.08.13
알고리즘 - 10. 검색(Search)  (0) 2009.08.13
52. 정수형인덱서와 문자열인덱서  (0) 2009.08.13
Posted by holland14
:

// 병합(MERGE): 두개의 배열을 합치기(정렬하면서 합치기???)
// 오름차순으로 나열된 두 그룹의 데이터를 한 그룹의 데이터롤 병합한다.
//(1) 데이터 a, b 중에 어느 한 쪽이 끝에 도달할 때까지 다음을 반복
//(2) a(i)와 b(j)를 비교해서 작은쪽을 c(K)에 복사하고 작은 쪽 번호를 +1한다.
//(3) 둘 중에 아직 끝까지 도달하지 않은 데이터를 끝까지 복사한다.
using System;

public class 병합정렬
{
    public static void Main()
    {
        //[1] Input : 원본 데이터가 정렬되어있다고 가정
        int[] first = { 1, 3, 5 };
        int[] second = { 2, 4 };
        int[] merge = new int[first.Length + second.Length]; // MERGE될 배열
        int i = 0; int j = 0; int k = 0;
        int M = first.Length;
        int N = second.Length;
        //[2] Process
        while (i < M && j < N) // 모두 끝에 도달할 때까지
        {
            if (first[i] <= second[j])
            {
                merge[k++] = first[i++];
            }
            else
            {
                merge[k++] = second[j++];
            }
        }
        while (i < M) // 첫번째 배열이 끝까지 도달할 때까지
        {
            merge[k++] = first[i++];
        }
        while (j < N) // 두번째 배열이 끝까지 도달할 때까지
        {
            merge[k++] = second[j++];
        }

        //[3] Output
        for (i = 0; i < merge.Length; i++)
        {
            Console.WriteLine(merge[i]); // 1, 2, 3, 4, 5 출력되도록...
        }
    }
}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

54. 이벤트(Event)  (0) 2009.08.13
53. 대리자(Delegate)  (0) 2009.08.13
알고리즘 - 10. 검색(Search)  (0) 2009.08.13
52. 정수형인덱서와 문자열인덱서  (0) 2009.08.13
51. 인덱서(Indexer)  (0) 2009.08.13
Posted by holland14
: