C#교과서 마스터하기 40. 클래스 라이브러와 닷넷 스탠다드

min seung moon·2021년 7월 15일
0

C#

목록 보기
42/54

https://www.youtube.com/watch?v=4kKa7qxd4cc&list=PLO56HZSjrPTB4NxAsEP8HRk6YKBDLbp7m&index=75

1. 클래스 라이브러와 닷넷 스탠다드

  • 클래스 라이브러(Class Library), 나만의 라이브러리 생성
    • 닷넷 스탠다드(.NET Standard)를 활용

2. 프로젝트

01. 빈 솔루션 프로젝트 생성

  • 라이브러리, 패키지 만들 때 사용




  • 빌드 해보기

  • 새 클래스 만들기

02. SelectionSort 메서드 만들기

  • Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DulAlgorithm
{
    class Algorithm
    {
        public static int[] SelectionSort(int[] numbers)
        {
            // [1] Input
            int N = numbers.Length;

            // [2] Process
            for(int i = 0; i < N - 1; i++)
            {
                for(int j = i + 1; j < N; j++) // 부등호 방향 : 오름차순(>), 내림차순(<)
                {
                    if(numbers[i] > numbers[j])
                    {
                        int temp = numbers[i];
                        numbers[i] = numbers[j];
                        numbers[j] = temp;
                    }
                }
            }

            // [3] Output
            return numbers;
        }
    }
}

03. test Project 생성(콘솔 앱)



-1. 외부 라이브러리 연결(종속성에 추가)

  • 같은 솔루션의 라이브러리 추가


-2. test 해보기

using System;

namespace DulAlgorithm.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // [1] Input
            int[] data = { 1, 4, 3, 2, 5 };

            // [2] Process
            int[] numbers = DulAlgorithm.Class1.SelectionSort(data);

            // [3] Output
            foreach(int number in numbers)
            {
                Console.WriteLine(number);
            }
        }
    }
}

04. test Proejct(windows Forms App(.Net Core))

-1. 프로젝트 생성


-2. Form1.cs[Design]에 버튼 추가

-3. Form1.cs 메서드 추가

  • button 2번 클릭
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DulAlgorithm.WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            // [1] Input
            int[] data = { 1, 4, 3, 2, 5 };

            // [2] Process
            int[] numbers = DulAlgorithm.Algorithm.SelectionSort(data);

            // [3] Output
            MessageBox.Show(numbers[1].ToString());
        }
    
    }
}


profile
아직까지는 코린이!

0개의 댓글