Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    A clumsy attempt with two overloaded constructors and an illegal constructor.Lecture 4 - slide 28 : 29
Program 3
using System;
using System.Collections;

public struct Interval{

  private readonly int from, to;
  private readonly bool empty;

  // Construct a non-empty interval [from - to].
  public Interval(int from, int to){
    this.empty = false;
    this.from = from;
    this.to = to;
  }

  // Construct an empty interval. The parameter is a dummy.
  public Interval(int notUsed){
    this.empty = true;
    this.from = 0;  // not really used
    this.to = 0;    // not really used
  }

  // Illegal constructor. Compile-time error.
  // Structs cannot contain explicit parameterless constructors
  public Interval(){
    this.empty = true;
    this.from = 0; 
    this.to = 0;   
  }    

  // Other Interval operations not shown   
}