public void Run() { MyNullable <int> n1 = new MyNullable <int>(5); MyNullable <int> n2 = 5; Console.WriteLine((int)n1 + (int)n2); }
public void ShouldNotReturnNullForValueType() { var myInt = new MyNullable <int>(15); Assert.IsNotNull(Utility.Box(myInt)); Assert.AreEqual(15, Utility.Box(myInt)); }
public void TypedRefTest() { var n = new MyNullable <double>(); MyNullable <double> .SetValue(__makeref(n), 4.0); Assert.That(n.value, Is.EqualTo(4.0)); }
public void Can_be_comparedi_with_operator_equal_equals() { var myNullable = new MyNullable<int>(1); var myNullable2 = new MyNullable<int>(1); Check.That(myNullable == myNullable2).IsTrue(); Check.That(myNullable == myNullable2).IsTrue(); var myNullable3 = new MyNullable<int>(2); Check.That(myNullable == myNullable3).IsFalse(); }
public IEnumerable <IArgumentScope> Enumerate() { MyNullable <SimpleStack> head = Stack; while (head != null) { yield return(head.Value.Value); head = head.Value.Previous; } }
/// <summary> /// Pushes value on the stack. /// Stack change is only valid for current variable lifetime since everything is allocated on stack. /// </summary> /// <param name="value">Value to be pushed on stack.</param> public void Push(IArgumentScope value) { SimpleStack newStack = new SimpleStack { Previous = null, Value = value, }; Stack = new MyNullable <SimpleStack>() { Value = newStack, }; }
static void Main(string[] args) { // 01 Person Person person1 = new Person("Bob"); // call the ctor Person person2 = "Mary"; // implicit conversion of String to Person string name = person2; // 02 Birthday Birthday birthday1 = new Birthday(); // call the ctor Birthday birthday2 = new DateTime(1970, 6, 2); // implicit conversion of DateTime to Birthday DateTime birthdate = birthday2; // implicit conversion of Birthday to DateTime int age = (int)birthday2; // explicit conversion of Birthday to Int32 // 03 AwesomeNumber short s = 5; AwesomeNumber number1 = s; // implicit short AwesomeNumber number2 = 5; // implicit integer AwesomeNumber number3 = (AwesomeNumber)2.0; // explicit double AwesomeNumber number4 = (AwesomeNumber)5.0m; // explicit decimal // 03b NotSoAwesomeNumber NotSoAwesomeNumber notSoAwesomeNumber = 5.3; double myOrigValue = notSoAwesomeNumber; // Uh-oh, only get 5 back. // Two ways to initialize the Nullable<T> struct var date0a = (DateTime?)null; var date0b = new Nullable<DateTime>(); //04 MyNullable<T> var date1 = new MyNullable<DateTime>(); Console.WriteLine(String.Concat("Date 1 Value: ", date1.HasValue ? date1.Value.ToShortDateString() : "N/A")); // output> "Date 1 Value: N/A" MyNullable<DateTime> date2 = DateTime.Now; Console.WriteLine(String.Concat("Date 2 Value: ", date2.HasValue ? date2.Value.ToShortDateString() : "N/A")); // output> "Date 2 Value: 2/11/2015" DateTime getMyDate2 = (DateTime)date2; Console.ReadLine(); }
public ForkLift() { x = 1; x++; y = new MyNullable <int>(); }
public void operator_equals_btw_nullable_and_value_works() { var myNullable = new MyNullable<int>(1); Check.That(myNullable == 1).IsEqualTo(true); Check.That(myNullable == 2).IsEqualTo(false); }
public void ShouldReturnNullForValueType() { var myInt = new MyNullable <int>(); Assert.IsNull(Utility.Box(myInt)); }