コード例 #1
0
ファイル: Int16Storage.cs プロジェクト: dox0/DotNet471RS3
        public override int CompareValueTo(int recordNo, object value)
        {
            System.Diagnostics.Debug.Assert(0 <= recordNo, "Invalid record");
            System.Diagnostics.Debug.Assert(null != value, "null value");

            if (NullValue == value)
            {
                return(HasValue(recordNo) ? 1 : 0);
            }

            Int16 valueNo1 = values[recordNo];

            if ((defaultValue == valueNo1) && !HasValue(recordNo))
            {
                return(-1);
            }
            return(valueNo1.CompareTo((Int16)value));
            //return(valueNo1 - valueNo2); // copied from Int16.CompareTo(Int16)
        }
コード例 #2
0
        public GameField(Game game)
            : base(game)
        {
            this.camera = game.GetService <CameraService>();
            game.RegisterGameService <PickingService>(out this.pickingService, true);
            if (MAP_WIDTH.CompareTo(MAP_HEIGHT) != 0)
            {
                throw new Exception("The width and the height of the field must be equal");
            }
            this.cellVertices = new VertexPositionColor[8];

            this.Game.RegisterGameComponent <ResourcesHUD>(out this.resourcesHUD, true, true);
            this.Game.RegisterGameComponent <BuildingsParent>(out this.buildingsParent, true, true);
            this.buildingsParent.SetParent(this, ref this.resourcesHUD);
            this.Game.RegisterGameComponent <ResourcesParent>(out this.resourcesParent, true, true);
            this.resourcesParent.SetParent(this, ref this.resourcesHUD);
            this.listOfTypes            = GameFieldHelper.GetResourcesNeeded(this.CheckResources, this.DecreaseResources);
            this.typeOfBuildingSelected = CellState.Forbidden;
            this.Game.RegisterGameComponent <HumansParent>(out this.humansParent, true, true);
            this.humansParent.SetParent(this);
        }
コード例 #3
0
ファイル: SortMove.cs プロジェクト: CNHume/Samples
        // Returns -1: if this < obj, 1: if this > obj, else 0: if this == obj
        public Int32 CompareTo(Object obj)
        {
            //if (obj is null) return 1;
            if (obj is SortMove)
            {
                var sm = (SortMove)obj;
                // Prefer greater Score
                var better = Value.CompareTo(sm.Value);
#if StableSort
                // Prefer lesser Index
                var sense = better == 0 ? -Index.CompareTo(sm.Index) : better;
#else
                var sense = better;
#endif
                return(sense);
            }
            else
            {
                throw new ArgumentException("Object is not a SortMove");
            }
        }
コード例 #4
0
 /// <summary>
 ///     A T extension method that check if the value is between inclusively the minValue and maxValue.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="minValue">The minimum value.</param>
 /// <param name="maxValue">The maximum value.</param>
 /// <returns>true if the value is between inclusively the minValue and maxValue, otherwise false.</returns>
 /// ###
 /// <typeparam name="T">Generic type parameter.</typeparam>
 public static bool InRange(this Int16 @this, Int16 minValue, Int16 maxValue)
 {
     return(@this.CompareTo(minValue) >= 0 && @this.CompareTo(maxValue) <= 0);
 }
コード例 #5
0
    public Boolean runTest()
    {
        Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
        int    iCountErrors    = 0;
        int    iCountTestcases = 0;
        String strLoc          = "Loc_000oo";
        Int16  in2a            = (Int16)0;
        Int16  in2b            = (Int16)0;
        short  sh2a            = (short)0;
        short  sh2b            = (short)0;

        try {
            do
            {
                strLoc = "Loc_122fj";
                sh2a   = (short)5;
                sh2b   = (short)5;
                in2a   = (Int16)(sh2a);
                in2b   = (Int16)(sh2b);
                iCountTestcases++;
                if (in2a.CompareTo(in2b) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_873ye!");
                }
                strLoc = "Loc_312je";
                in2a   = Int16.MinValue;
                in2b   = Int16.MinValue;
                iCountTestcases++;
                if (in2a.CompareTo(in2b) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_399ad!");
                }
                strLoc = "Loc_348je";
                sh2a   = (short)0;
                sh2b   = (short)0;
                in2a   = (Int16)sh2a;
                in2b   = (Int16)sh2b;
                iCountTestcases++;
                if (in2a.CompareTo(in2b) != 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_838su! , in2a==" + in2a);
                }
                strLoc = "Loc_938jd";
                in2a   = Int16.MaxValue;
                in2b   = Int16.MinValue;
                iCountTestcases++;
                if (in2a.CompareTo(in2b) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_387aj!");
                }
                strLoc = "Loc_578sj";
                sh2a   = (short)11;
                sh2b   = (short)10;
                in2a   = (Int16)sh2a;
                in2b   = (Int16)sh2b;
                iCountTestcases++;
                if (in2a.CompareTo(in2b) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_428ju!");
                }
                strLoc = "Loc_743je";
                sh2a   = (short)10;
                sh2b   = (short)11;
                in2a   = (Int16)sh2a;
                in2b   = (Int16)sh2b;
                iCountTestcases++;
                if (in2a.CompareTo(in2b) >= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_218sk!");
                }
                strLoc = "Loc_939eu";
                in2a   = Int16.MinValue;
                in2b   = Int16.MaxValue;
                iCountTestcases++;
                if (in2a.CompareTo(in2b) >= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_377as!");
                }
                strLoc = "Loc_377su";
                iCountTestcases++;
                try {
                    in2a.CompareTo(null);
                } catch (ArgumentException) {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_382hf! , return==" + in2a.CompareTo(null));
                }
                strLoc = "Loc_838dh";
                in2a   = (Int16)5;
                iCountTestcases++;
                if (in2a.CompareTo(null) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_237fe! ,result==" + in2a.CompareTo(null));
                }
                strLoc = "Loc_878ju";
                in2a   = (Int16)0;
                iCountTestcases++;
                if (in2a.CompareTo(null) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_737sa! ,result==" + in2a.CompareTo(null));
                }
                strLoc = "Loc_573kd";
                sh2a   = (short)-2;
                in2a   = (Int16)(sh2a);
                iCountTestcases++;
                if (in2a.CompareTo(null) <= 0)
                {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_727aj! ,result==" + in2a.CompareTo(null));
                }
                strLoc = "Loc_109cu";
                in2a   = (Int16)5;
                iCountTestcases++;
                try {
                    in2a.CompareTo((Int64)5);
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_209cu! , result==" + in2a.CompareTo((Int64)5));
                } catch (ArgumentException) {
                } catch (Exception exc) {
                    iCountErrors++;
                    Console.WriteLine(s_strTFAbbrev + "Err_109ux! Unexpected Exception == " + exc.ToString());
                }
                in2a = -12;
                ++iCountTestcases;
                if (in2a.CompareTo((Int16)66) >= 0)
                {
                    ++iCountErrors;
                    Console.Error.WriteLine("POINTTOBREAK:  Error Err_337uf!");
                }
                strLoc = "Loc_938cd";
                in2a   = (Int16)(-12);
                in2a   = (Int16)in2a.CompareTo((Int16)(-77));
                ++iCountTestcases;
                if (!(in2a > (Int16)0))
                {
                    ++iCountErrors;
                    Console.Error.WriteLine("POINTTOBREAK:  Error Err_411wq!  in2a==" + in2a);
                }
            } while (false);
        } catch (Exception exc_general) {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general);
        }
        if (iCountErrors == 0)
        {
            Console.Error.WriteLine("paSs.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.Error.WriteLine("FAiL!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
コード例 #6
0
 /// <summary>
 ///     A T extension method that check if the value is between (exclusif) the minValue and maxValue.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="minValue">The minimum value.</param>
 /// <param name="maxValue">The maximum value.</param>
 /// <returns>true if the value is between the minValue and maxValue, otherwise false.</returns>
 /// ###
 /// <typeparam name="T">Generic type parameter.</typeparam>
 public static bool Between(this Int16 @this, Int16 minValue, Int16 maxValue)
 {
     return(minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1);
 }
コード例 #7
0
 public int CompareTo(wshort value)
 {
     return(val.CompareTo(value.val));
 }
コード例 #8
0
 private static void Compare_Int16(Int16 a, Int16 b) =>
 AssertEquals(a.CompareTo(b), Comparer <Int16> .Default.Compare(a, b));
コード例 #9
0
ファイル: cat.cs プロジェクト: zhamppx97/dotnet-api-docs
    public static void Main()
    {
        string nl  = Environment.NewLine;
        string msg = "{0}The following is the result of using the generic and non-generic{0}" +
                     "versions of the CompareTo method for several base types:{0}";

        DateTime now = DateTime.Now;
// Time span = 11 days, 22 hours, 33 minutes, 44 seconds
        TimeSpan tsX = new TimeSpan(11, 22, 33, 44);
// Version = 1.2.333.4
        Version versX = new Version("1.2.333.4");
// Guid = CA761232-ED42-11CE-BACD-00AA0057B223
        Guid guidX = new Guid("{CA761232-ED42-11CE-BACD-00AA0057B223}");

        Boolean  a1 = true, a2 = true;
        Byte     b1 = 1, b2 = 1;
        Int16    c1 = -2, c2 = 2;
        Int32    d1 = 3, d2 = 3;
        Int64    e1 = 4, e2 = -4;
        Decimal  f1 = -5.5m, f2 = 5.5m;
        Single   g1 = 6.6f, g2 = 6.6f;
        Double   h1 = 7.7d, h2 = -7.7d;
        Char     i1 = 'A', i2 = 'A';
        String   j1 = "abc", j2 = "abc";
        DateTime k1 = now, k2 = now;
        TimeSpan l1 = tsX, l2 = tsX;
        Version  m1 = versX, m2 = new Version("2.0");
        Guid     n1 = guidX, n2 = guidX;

// The following types are not CLS-compliant.
        SByte  w1 = 8, w2 = 8;
        UInt16 x1 = 9, x2 = 9;
        UInt32 y1 = 10, y2 = 10;
        UInt64 z1 = 11, z2 = 11;

//
        Console.WriteLine(msg, nl);
        try
        {
// The second and third Show method call parameters are automatically boxed because
// the second and third Show method declaration arguments expect type Object.

            Show("Boolean:  ", a1, a2, a1.CompareTo(a2), a1.CompareTo((Object)a2));
            Show("Byte:     ", b1, b2, b1.CompareTo(b2), b1.CompareTo((Object)b2));
            Show("Int16:    ", c1, c2, c1.CompareTo(c2), c1.CompareTo((Object)c2));
            Show("Int32:    ", d1, d2, d1.CompareTo(d2), d1.CompareTo((Object)d2));
            Show("Int64:    ", e1, e2, e1.CompareTo(e2), e1.CompareTo((Object)e2));
            Show("Decimal:  ", f1, f2, f1.CompareTo(f2), f1.CompareTo((Object)f2));
            Show("Single:   ", g1, g2, g1.CompareTo(g2), g1.CompareTo((Object)g2));
            Show("Double:   ", h1, h2, h1.CompareTo(h2), h1.CompareTo((Object)h2));
            Show("Char:     ", i1, i2, i1.CompareTo(i2), i1.CompareTo((Object)i2));
            Show("String:   ", j1, j2, j1.CompareTo(j2), j1.CompareTo((Object)j2));
            Show("DateTime: ", k1, k2, k1.CompareTo(k2), k1.CompareTo((Object)k2));
            Show("TimeSpan: ", l1, l2, l1.CompareTo(l2), l1.CompareTo((Object)l2));
            Show("Version:  ", m1, m2, m1.CompareTo(m2), m1.CompareTo((Object)m2));
            Show("Guid:     ", n1, n2, n1.CompareTo(n2), n1.CompareTo((Object)n2));
//
            Console.WriteLine("{0}The following types are not CLS-compliant:", nl);
            Show("SByte:    ", w1, w2, w1.CompareTo(w2), w1.CompareTo((Object)w2));
            Show("UInt16:   ", x1, x2, x1.CompareTo(x2), x1.CompareTo((Object)x2));
            Show("UInt32:   ", y1, y2, y1.CompareTo(y2), y1.CompareTo((Object)y2));
            Show("UInt64:   ", z1, z2, z1.CompareTo(z2), z1.CompareTo((Object)z2));
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
コード例 #10
0
ファイル: Entity.cs プロジェクト: BanMing/BMBaseCore
 public int CompareTo(Entity <TEntity> other)
 {
     return(Index.CompareTo(other.Index));
 }
コード例 #11
0
 public static Int16 of(Int16 left, Int16 right)
 {
     return(left.CompareTo(right) < 0 ? right : left);
 }
コード例 #12
0
 public int CompareTo(short other)
 {
     return(value.CompareTo(other));
 }
コード例 #13
0
        public static int compareTo(object o1, object o2)
        {
            try {
                if (o1 == null || o2 == null)
                {
                    return(0);
                }
                if (!Types.Equals(o1, o1))
                {
                    return(0);
                }

                if (o1 is bool)
                {
                    bool v1 = (bool)o1;
                    bool v2 = (bool)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Boolean)
                {
                    Boolean v1 = (Boolean)o1;
                    bool    v2 = (Boolean)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is byte)
                {
                    byte v1 = (byte)o1;
                    byte v2 = (byte)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Byte)
                {
                    Byte v1 = (Byte)o1;
                    Byte v2 = (Byte)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is short)
                {
                    short v1 = (short)o1;
                    short v2 = (short)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Int16)
                {
                    Int16 v1 = (Int16)o1;
                    Int16 v2 = (Int16)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is UInt16)
                {
                    UInt16 v1 = (UInt16)o1;
                    UInt16 v2 = (UInt16)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is int)
                {
                    int v1 = (int)o1;
                    int v2 = (int)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Int32)
                {
                    Int32 v1 = (Int32)o1;
                    Int32 v2 = (Int32)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is UInt32)
                {
                    UInt32 v1 = (UInt32)o1;
                    UInt32 v2 = (UInt32)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is long)
                {
                    long v1 = (long)o1;
                    long v2 = (long)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is Int64)
                {
                    Int64 v1 = (Int64)o1;
                    Int64 v2 = (Int64)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is UInt64)
                {
                    UInt64 v1 = (UInt64)o1;
                    UInt64 v2 = (UInt64)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is float)
                {
                    float v1 = (float)o1;
                    float v2 = (float)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is double)
                {
                    double v1 = (double)o1;
                    double v2 = (double)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is string)
                {
                    string v1 = (string)o1;
                    string v2 = (string)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is String)
                {
                    String v1 = (String)o1;
                    String v2 = (String)o2;
                    return(v1.CompareTo(v2));
                }
                else if (o1 is DateTime)
                {
                    DateTime v1 = (DateTime)o1;
                    DateTime v2 = (DateTime)o2;
                    return(v1.CompareTo(v2));
                }
            } catch (Exception) {
            }
            return(0);
        }
コード例 #14
0
ファイル: Year.cs プロジェクト: hanifhn/Qowaiv
 /// <summary>Compares this instance with a specified year and indicates
 /// whether this instance precedes, follows, or appears in the same position
 /// in the sort order as the specified year.
 /// </summary>
 /// <param name="other">
 /// The year to compare with this instance.
 /// </param>
 /// <returns>
 /// A 32-bit signed integer that indicates whether this instance precedes, follows,
 /// or appears in the same position in the sort order as the value parameter.
 /// </returns>
 public int CompareTo(Year other)
 {
     return(m_Value.CompareTo(other.m_Value));
 }
コード例 #15
0
 public Int32 Compare(Int16 a, Int16 b)
 {
     return(a.CompareTo(b));
 }