Пример #1
0
    public static LimitedInt operator +(LimitedInt x, double y)
    {
        LimitedInt li = new LimitedInt();

        li.TheValue = x.TheValue + (int)y;
        return(li);
    }
Пример #2
0
    public static LimitedInt operator -(LimitedInt x, LimitedInt y)
    {
        LimitedInt li = new LimitedInt();

        li.TheValue = x.TheValue - y.TheValue;
        return(li);
    }
Пример #3
0
    static void Main()                                      // Main
    {
        LimitedInt li    = 500;                             // Convert 500 to LimitedInt
        int        value = li;                              // Convert LimitedInt to int

        Console.WriteLine($"li: { li.TheValue }, value: { value }");
    }
Пример #4
0
    static void Main()
    {
        LimitedInt li    = (LimitedInt)500;
        int        value = (int)li;

        Console.WriteLine("li: {0}, value: {1}", li.TheValue, value);
    }
Пример #5
0
    public static LimitedInt operator -(LimitedInt argLHS, int argRHS)
    {
        LimitedInt myLimitedInt = new LimitedInt(argLHS);

        myLimitedInt.Current -= argRHS;
        return(myLimitedInt);
    }
Пример #6
0
    public static LimitedInt operator -(LimitedInt x)
    {
        LimitedInt li = new LimitedInt();

        li.TheValue = 0;
        return(li);
    }
Пример #7
0
    static void Main()
    {
        LimitedInt li    = (LimitedInt)500;
        int        value = (int)li;

        Console.WriteLine($"li: { li.TheValue }, value: { value }");
    }
Пример #8
0
        static void Main()
        {
            LimitedInt li   = 5;
            int        Five = li;

            Console.WriteLine("li: {0}, Five: {1}", li.TheValue, Five);
        }
Пример #9
0
    public static LimitedInt operator -(LimitedInt x)
    {
        // In this strange class, negating a value just sets its value to 0.
        LimitedInt li = new LimitedInt();

        li.TheValue = 0;
        return(li);
    }
Пример #10
0
    static void Main()              // Main
    {
        LimitedInt li    = 500;     // Convert 500 to LimitedInt
        int        value = li;      // Convert LimitedInt to int

        Console.WriteLine("li: {0}, value: {1}", li.TheValue,
                          value);
    }
Пример #11
0
        public void MaxTest()
        {
            var gene = new LimitedInt(1, 10);

            gene.Value = 561;
            Assert.AreEqual(10, gene.Value);
            gene.Value++;
            Assert.AreEqual(10, gene.Value);
        }
Пример #12
0
        public void MinTest()
        {
            var gene = new LimitedInt(1, 10);

            gene.Value = -2;
            Assert.AreEqual(1, gene.Value);
            gene.Value--;
            Assert.AreEqual(1, gene.Value);
        }
Пример #13
0
        public void _03()
        {
            var limitedInt01 = new LimitedInt {
                TheValue = 10
            };
            var limitedInt02 = limitedInt01 + 10;

            Assert.Equal(20, limitedInt02.TheValue);
        }
Пример #14
0
        public void _01()
        {
            LimitedInt limitedInt = 500;

            Assert.Equal(100, limitedInt.TheValue);

            int i01 = limitedInt;

            Assert.Equal(100, i01);
        }
Пример #15
0
        public void _02()
        {
            var limitedInt01 = new LimitedInt {
                TheValue = 20
            };
            var limitedInt02 = new LimitedInt {
                TheValue = 10
            };
            var limitedInt03 = limitedInt01 - limitedInt02;

            Assert.Equal(10, limitedInt03.TheValue);
        }
Пример #16
0
        public void _01()
        {
            var limitedInt01 = new LimitedInt {
                TheValue = 100
            };

            Assert.Equal(100, limitedInt01.TheValue);

            var limitedInt02 = -limitedInt01;

            Assert.Equal(0, limitedInt02.TheValue);
        }
Пример #17
0
        private Color GetColorFromValue(double normalizedValue, bool biggerRed = true)
        {
            var percent = new LimitedInt(0, 100)
            {
                Value = (int)Math.Round(100 * normalizedValue, MidpointRounding.AwayFromZero)
            };

            if (!biggerRed)
            {
                percent.Value = 100 - percent;
            }
            return(Color.FromArgb(255 * percent / 100, (255 * (100 - percent)) / 100, 0));
        }
Пример #18
0
        public void MinusOperatorTest()
        {
            var gene1 = new LimitedInt(0, 10)
            {
                Value = 4
            };
            var gene2 = new LimitedInt(0, 10)
            {
                Value = 1
            };

            Assert.AreEqual(3, gene1 - gene2);
        }
Пример #19
0
        public void _01()
        {
            //----------------------------------------------------------------------------------------------------
            // 显式类型转换必须使用 cast operator(也就是圆括号)
            //----------------------------------------------------------------------------------------------------
            LimitedInt limitedInt = (LimitedInt)500;

            Assert.Equal(100, limitedInt.TheValue);

            var i01 = (int)limitedInt;

            Assert.Equal(100, i01);
        }
Пример #20
0
    static void Main()
    {
        LimitedInt li1 = new LimitedInt();
        LimitedInt li2 = new LimitedInt();
        LimitedInt li3 = new LimitedInt();

        li1.TheValue = 10;
        li2.TheValue = 26;

        Console.WriteLine("li1: {0}, li2: {1}", li1.TheValue, li2.TheValue);
        li3 = -li1;
        Console.WriteLine("-{0} = {1}", li1.TheValue, li3.TheValue);
        li3 = li2 - li1;
        Console.WriteLine(" {0} - {1} = {2}", li2.TheValue, li1.TheValue, li3.TheValue);
        li3 = li1 - li2;
        Console.WriteLine(" {0} - {1} = {2}", li1.TheValue, li2.TheValue, li3.TheValue);
    }
Пример #21
0
        public void Demo18()
        {
            //隐式定义类型转换,显式:将implicit改为explicit
            LimitedInt li = 400;
            int        i  = li;

            Console.WriteLine("LimitedInt: {0},int: {1}", li.Value, i);

            //重载运算符
            LimitedInt nli = -li;
            LimitedInt num = 44;
            LimitedInt end = li - num;
            LimitedInt sum = end + 2.3;

            Console.WriteLine("取负数{0}", nli.Value);
            Console.WriteLine("相减{0}", end.Value);
            Console.WriteLine("加Double{0}", sum.Value);
        }
Пример #22
0
    static void Main()
    {
        LimitedInt li1 = new LimitedInt();
        LimitedInt li2 = new LimitedInt();
        LimitedInt li3 = new LimitedInt();

        li1.TheValue = 10; li2.TheValue = 26;
        Console.WriteLine($" li1: { li1.TheValue }, li2: { li2.TheValue }");

        li3 = -li1;
        Console.WriteLine($"-{ li1.TheValue } = { li3.TheValue }");

        li3 = li2 - li1;
        Console.WriteLine($" { li2.TheValue } - { li1.TheValue } = { li3.TheValue }");

        li3 = li1 - li2;
        Console.WriteLine($" { li1.TheValue } - { li2.TheValue } = { li3.TheValue }");
    }
Пример #23
0
 public LimitedInt(LimitedInt argCopy)
 {
     min     = argCopy.min;
     max     = argCopy.max;
     current = argCopy.current;
 }
Пример #24
0
 public LimitedInt(LimitedInt argCopy)
 {
     min = argCopy.min;
     max = argCopy.max;
     current = argCopy.current;
 }
Пример #25
0
 public static LimitedInt operator -(LimitedInt argLHS, int argRHS)
 {
     LimitedInt myLimitedInt = new LimitedInt(argLHS);
     myLimitedInt.Current -= argRHS;
     return myLimitedInt;
 }
Пример #26
0
 private Color GetColorFromValue(LimitedInt gene, bool biggerRed = true)
 {
     return(GetColorFromValue(gene.NormalizedValue, biggerRed));
 }
Пример #27
0
 public bool CheckRng(LimitedInt range)
 {
     return(CheckRng(range.Value, range.Min, range.Max));
 }