Visual Studio 2008에서 파일 --> 새로만들기 --> 새 프로젝트 --> "새 프로젝트 추가"창에서 "Visual C# --> Windows"로 선택한 후 --> "Visual Studio에 설치되어 있는 템플릿"에서 "클래스 라이브러리"선택 후 이름(여기서는 "psh.Library"로 클래스 라이브러리의 이름 지정)과 저장위치 정한 후 프로젝트 만들기
--> '솔루션 탐색기'의 "psh.Labrary"에서 Class1.cs파일 삭제 후 다시 "psh.Labrary" 우클릭 --> 추가
--> 새항목 --> '새 항목 추가'창에서 "클래스"로 선택하고 파일명은 "Board.cs"(게시판)로 지정하여 클래스파일 생성함. --> "Board.cs"에 아래의 코드 입력하여 "나만의 라이브러리(Labrary)" 만들기(만들어 둔 나만의 라이브러리를 다른 클래스에 삽입하여 기능을 구현할 수 있다. 하지만 여기서 작성한 코드는 작성한 클래스인 "Board.cs"에서는 실행될 수는 없다. 왜냐면 이 코드들은 "클래스 라이브러리" 이므로... 나중에 다른 예제에서 여기서 만들어 둔 나만의 라이브러리를 활용할 수 있는 부분이 있으면 다른 클래스에서 적절히 활용하여 구현하면 된다.)



==> Board.cs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace psh.Library
{
    public class Board
    {
        /// <summary>
        ///  파일명(test.gif)을 넘겨주면 이미지 파일인지 아닌지를 결정
        /// </summary>
        /// <param name="fileName">.jpeg, .jpg, .png, .gif</param>
        /// <returns></returns>
        public static bool IsPhoto(string fileName)
        {
            // 완성해보세요~
            string temp = "";
            temp = fileName.Substring(fileName.LastIndexOf(".") + 1);
            if (temp == "jpeg" || temp == "jpg" || temp == "png" || temp == "gif")
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        ///  1048576 이 넘겨오면, 1MB 반환 : 즉, Byte, KB, MB, GB단위로...
        /// </summary>
        /// <param name="fileSize"></param>
        /// <returns></returns>
        public static string GetFileSize(long fileSize)
        {
            long temp = 0;
            long Byte = 0;
            long KB = 0;
            long MB = 0;
            long GB = 0;
            string total = "";
            temp = fileSize;
           
            if (temp >= 1073741824)
            {
                GB = temp / 1073741824;     // GB 단위
                temp -= GB * 1073741824;
                total += Convert.ToString(GB) + "GB ";
            }
            if (temp >= 1048576)
            {
                MB = temp / 1048576;        // MB 단위
                temp -= MB * 1048576;
                total += Convert.ToString(MB) + "MB ";
            }
            if (temp >= 1024)
            {
                KB = temp / 1024;           // KB 단위
                temp -= KB * 1024;
                total += Convert.ToString(KB) + "KB ";
            }
            if (temp > 0)
            {
                Byte = temp;
                total += Convert.ToString(Byte) + "Byte";   // Byte 단위
            }
            return total;
        }
    }
}





Posted by holland14
: