C # General Interval class

Source: Internet
Author: User

 Public classZone<t>whereT:icomparable<t>    {        /// <summary>        ///. ctor/// </summary>         PublicZone () {}/// <summary>        ///. ctor/// </summary>        /// <param name= "briefstring" >strings, such as ("3-5")</param>         PublicZone (stringbriefstring) {            //T min, max;            string[] arr = Briefstring.split ('-'); if(arr.) Length = =2)            {                if(typeof(T) = =typeof(int) ) {Min= (T) (Object)(int. Parse (arr[0])); Max= (T) (Object)(int. Parse (arr[1])); }                Else if(typeof(T) = =typeof(decimal) ) {Min= (T) (Object)(decimal. Parse (arr[0])); Max= (T) (Object)(decimal. Parse (arr[1]));            } Swap (); }        }        /// <summary>        ///. ctor///Call the following///var sdsd = "3-5"; ///var zone = new Zone<int>(SDSD, p = Int.)        Parse (p)); ///var zone2 = new Zone<decimal>(SDSD, p = decimal.)        Parse (p)); /// </summary>        /// <param name= "briefstring" >strings, such as ("3-5")</param>        /// <param name= "converter" >The conversion method.</param>         PublicZone (stringBriefstring, converter<string, t>Converter) {            //T min, max;            vararr = Briefstring.split ('-'); if(arr.) Length = =2) {Min= Converter (arr[0]); Max= Converter (arr[1]);            Swap (); }        }        /// <summary>        ///Small Value/// </summary>         PublicT Min {Get;Set; } /// <summary>        ///Large Value/// </summary>         PublicT Max {Get;Set; } /// <summary>        ///ToString ()/// </summary>        /// <returns></returns>         Public Override stringToString () {return string. Format ("{{min:{0},max:{1}}}", Min, Max); }        /// <summary>        ///returns a short string description/// </summary>        /// <returns></returns>         Public stringtobriefstring () {return string. Format ("{0}-{1}", Min, Max); }        Private voidSwap () {if(Min.compareto (Max) >0) {T temp=Max; Max=Min; Min=temp; }        }    }

C # General Interval class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.