public static LimitedInt operator +(LimitedInt x, double y) { LimitedInt li = new LimitedInt(); li.TheValue = x.TheValue + (int)y; return(li); }
public static LimitedInt operator -(LimitedInt x, LimitedInt y) { LimitedInt li = new LimitedInt(); li.TheValue = x.TheValue - y.TheValue; return(li); }
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 }"); }
static void Main() { LimitedInt li = (LimitedInt)500; int value = (int)li; Console.WriteLine("li: {0}, value: {1}", li.TheValue, value); }
public static LimitedInt operator -(LimitedInt argLHS, int argRHS) { LimitedInt myLimitedInt = new LimitedInt(argLHS); myLimitedInt.Current -= argRHS; return(myLimitedInt); }
public static LimitedInt operator -(LimitedInt x) { LimitedInt li = new LimitedInt(); li.TheValue = 0; return(li); }
static void Main() { LimitedInt li = (LimitedInt)500; int value = (int)li; Console.WriteLine($"li: { li.TheValue }, value: { value }"); }
static void Main() { LimitedInt li = 5; int Five = li; Console.WriteLine("li: {0}, Five: {1}", li.TheValue, Five); }
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); }
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); }
public void MaxTest() { var gene = new LimitedInt(1, 10); gene.Value = 561; Assert.AreEqual(10, gene.Value); gene.Value++; Assert.AreEqual(10, gene.Value); }
public void MinTest() { var gene = new LimitedInt(1, 10); gene.Value = -2; Assert.AreEqual(1, gene.Value); gene.Value--; Assert.AreEqual(1, gene.Value); }
public void _03() { var limitedInt01 = new LimitedInt { TheValue = 10 }; var limitedInt02 = limitedInt01 + 10; Assert.Equal(20, limitedInt02.TheValue); }
public void _01() { LimitedInt limitedInt = 500; Assert.Equal(100, limitedInt.TheValue); int i01 = limitedInt; Assert.Equal(100, i01); }
public void _02() { var limitedInt01 = new LimitedInt { TheValue = 20 }; var limitedInt02 = new LimitedInt { TheValue = 10 }; var limitedInt03 = limitedInt01 - limitedInt02; Assert.Equal(10, limitedInt03.TheValue); }
public void _01() { var limitedInt01 = new LimitedInt { TheValue = 100 }; Assert.Equal(100, limitedInt01.TheValue); var limitedInt02 = -limitedInt01; Assert.Equal(0, limitedInt02.TheValue); }
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)); }
public void MinusOperatorTest() { var gene1 = new LimitedInt(0, 10) { Value = 4 }; var gene2 = new LimitedInt(0, 10) { Value = 1 }; Assert.AreEqual(3, gene1 - gene2); }
public void _01() { //---------------------------------------------------------------------------------------------------- // 显式类型转换必须使用 cast operator(也就是圆括号) //---------------------------------------------------------------------------------------------------- LimitedInt limitedInt = (LimitedInt)500; Assert.Equal(100, limitedInt.TheValue); var i01 = (int)limitedInt; Assert.Equal(100, i01); }
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); }
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); }
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 }"); }
public LimitedInt(LimitedInt argCopy) { min = argCopy.min; max = argCopy.max; current = argCopy.current; }
public static LimitedInt operator -(LimitedInt argLHS, int argRHS) { LimitedInt myLimitedInt = new LimitedInt(argLHS); myLimitedInt.Current -= argRHS; return myLimitedInt; }
private Color GetColorFromValue(LimitedInt gene, bool biggerRed = true) { return(GetColorFromValue(gene.NormalizedValue, biggerRed)); }
public bool CheckRng(LimitedInt range) { return(CheckRng(range.Value, range.Min, range.Max)); }