블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

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

Category

Recent Post

Recent Comment

Archive

2009. 8. 13. 13:25 .Net Project/.Net 3.5 Sp1
반응형


using System;

public class 제네릭메서드
{
    public static void Swap(ref int a, ref int b)
    {
        int temp = a;
        a = b;
        b = temp;

    }
    public static void Main()
    {
        //input
        int[] data = { 5, 4, 9, 3, 8 };
        //int temp=0;

        //process
        for (int i = 0; i <= data.Length - 1; i++)
        {
            for (int j = 0; j < data.Length; j++)
            {
                if (data[i] < data[j])
                {
                    //temp = data[i];
                    //data[i] = data[j];
                    //data[j] = temp;
                    Swap(ref data[i], ref data[j]);
                }


            }

        }
        //output
        for (int i = 0; i < data.Length; i++)
        {
            Console.WriteLine("{0}", data[i]);
        }
    }

}


//=========제네릭 메서드 : 형식 매개변수 T를 사용, 여러개의 매개변수 동시 처리
using System;
using System.Collections.Generic;

public class 제네릭메서드
{
    private static void Swap<T>(ref T a, ref T b)
    {
        T temp = a;
        a = b;
        b = temp;
    }

  
    public static void Main()
    {
        //input
        string[] data = { "a","z","c","b","f" };
        //int temp=0;

        //process
        for (int i = 0; i <= data.Length - 1; i++)
        {
            for (int j = 0; j < data.Length; j++)
            {
                if (string.Compare(data[i], data[j]) < 0 )
                {
                    //temp = data[i];
                    //data[i] = data[j];
                    //data[j] = temp
;
                    Swap<string> (ref data[i], ref data[j]);
                }
            }
        }
        //output
        for (int i = 0; i < data.Length; i++)
        {
            Console.WriteLine("{0}", data[i]);
        }
    }
}


 

반응형

'.Net Project > .Net 3.5 Sp1' 카테고리의 다른 글

69장 JavaScript Event  (0) 2009.08.13
68장 익명(Anymous)  (0) 2009.08.13
66장 이벤트(Event)  (0) 2009.08.13
65장 델리게이트(delegate)  (0) 2009.08.13
64장 알고리즘(병합)  (0) 2009.08.12
posted by Magic_kit