'단위'에 해당되는 글 2건

  1. 2009/05/14 C# : Unit Class - File Size
  2. 2009/04/10 C# - Length unit class , 길이 관련 클래스
2009/05/14 23:51

C# : Unit Class - File Size

 

이전에 올렸던 Length 단위에 이어 두번째 File Size 관련된 단위입니다.

귀찮았는데 막상 파일사이즈를 보여야 할 일이 있어서

간단히 Property 를 이용해서 작성해 봤네요.

C# 프로퍼티(Property)의  가장 적절한 예가 아닌가 생각됩니다. ㅋㅋㅋ



    class FileSize

    {

        public enum UNITS { B, KB, MB, GB, TB }

 

        double b = 0;

        double kb = 0;

        double mb = 0;

        double gb = 0;

        double tb = 0;

 

        public double B

        {

            get

            {

                return this.b;

            }

            set

            {

                this.b = value;

                this.kb = this.b / 1024;

                this.mb = this.kb / 1024;

                this.gb = this.mb / 1024;

                this.tb = this.gb / 1024;

            }

        }

 

        public double KB

        {

            get

            {

                return this.kb;

            }

            set

            {

                this.kb = value;

                this.B = this.kb * 1024;

            }

        }

 

        public double MB

        {

            get

            {

                return this.mb;

            }

            set

            {

                this.mb = value;

                this.KB = this.mb * 1024;

            }

        }

 

        public double GB

        {

            get

            {

                return this.gb;

            }

            set

            {

                this.gb = value;

                this.MB = this.gb * 1024;

            }

        }

 

        public double TB

        {

            get

            {

                return this.tb;

            }

            set

            {

                this.tb = value;

                this.GB = this.tb * 1024;

            }

        }

 

        public FileSize(double size)

        {

            this.B = size;

        }

 

        public override string ToString()

        {

            string ret = string.Empty;

 

            if (b < 1024D)

            {

                ret = string.Format("{0}{1}", b, UNITS.B.ToString());

            }

            else if (kb < 1024D)

            {

                ret = string.Format("{0}{1}", kb, UNITS.KB.ToString());

            }

            else if (mb < 1024D)

            {

                ret = string.Format("{0}{1}", mb, UNITS.MB.ToString());

            }

            else if (gb < 1024D)

            {

                ret = string.Format("{0}{1}", gb, UNITS.GB.ToString());

            }

            else

            {

                ret = string.Format("{0}{1}", tb, UNITS.TB.ToString());

            }

 

            return ret;

        }

    }

 


저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License

'.NET > C#' 카테고리의 다른 글

Windows Service Debugging  (0) 2009/10/21
Unicode 한글 코드 표  (0) 2009/09/27
C# : Unit Class - File Size  (0) 2009/05/14
Memory usage of current thread on C# windows form app.  (0) 2009/04/23
C# : TextBox Auto Scrolling  (2) 2009/04/20
Better string.IsNullOrEmpty() ? How to do C#.NET 3.0  (0) 2009/04/14
올블로그추천버튼 블코추천버튼 블로그뉴스추천버튼 믹시추천버튼 한RSS추가버튼 구글리더기추천버튼


이 포스팅이 도움이 되었다면 구글에서 관련 정보를 찾아 보세요 ^^


Trackback 0 Comment 0

Trackback : http://i-ruru.com/trackback/468 관련글 쓰기

2009/04/10 00:30

C# - Length unit class , 길이 관련 클래스


CodeProject에 올라온 코드를 보던 중 유용한 클래스를 발견했다.

딱 보아도 한눈에 알 수 있는 길이 관련된 클래스
원본 길이 단위의 값을 넣고, 원하는 길위 단위로 값을 읽어오기만하면, 길이를 원하는 형식으로 변경할 수 있다.

꽤 유용하게 써먹을 듯?? 훗~

 

    public class Length

    {

        public enum UNITS{FEET=0,KM,METER,MILES}

        private double meter  = 0;

        private double km     = 0;

        private double ft     = 0;

        private double miles  = 0;

 

        public double Meter

        {

            get

            {

                return this.meter;

            }

            set

            {

                this.meter=value;

                this.km=this.meter/1000;

                this.ft=this.meter*3.2808;

                this.miles=this.meter*6.2e-4;

            }

        }

        public double Km

        {

            get

            {

                return this.km;

            }

            set

            {

                this.km=value;

                this.Meter=this.km*1000;

            }

        }

        public double Ft

        {

            get

            {

                return this.ft;

            }

            set

            {

                this.ft=value;

                this.Meter=this.ft/3.2808;

            }

        }

        public double Miles

        {

            get

            {

                return this.miles;

            }

            set

            {

                this.miles=value;

                this.meter=this.miles/6.2e-4;

            }

        }

    }


저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License
올블로그추천버튼 블코추천버튼 블로그뉴스추천버튼 믹시추천버튼 한RSS추가버튼 구글리더기추천버튼


이 포스팅이 도움이 되었다면 구글에서 관련 정보를 찾아 보세요 ^^


Trackback 0 Comment 0

Trackback : http://i-ruru.com/trackback/444 관련글 쓰기