Lecture overview -- Keyboard shortcut: 'u'  Previous page: Procedures and Functions -- Keyboard shortcut: 'p'  Next page: Object-oriented programming in Visual Basic -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Page 38 : 43
Object-oriented Programming in C#
Introduction to C#
Combined C# and Visual Basic Programming

A client written in Visual Basic and a server written in C#

using System;

public class Die {
  private int numberOfEyes;
  private Random randomNumberSupplier; 
  private const int maxNumberOfEyes = 6;

  public Die(){
    randomNumberSupplier = new Random(unchecked((int)DateTime.Now.Ticks));
    numberOfEyes = NewTossHowManyEyes();
  }   
    
  public void Toss(){
    numberOfEyes = NewTossHowManyEyes();
  }

  private int NewTossHowManyEyes (){
    return randomNumberSupplier.Next(1,maxNumberOfEyes + 1);
  }

  public int NumberOfEyes() {
    return numberOfEyes;
  }

  public override String ToString(){
    return String.Format("[{0}]", numberOfEyes);
  }
}     

A class Die programmed in C#.

Imports System

Module DieApplication

  Sub Main()
    Dim D1 as new Die()
    Dim D2 as new Die()
    D1.Toss()
    Console.WriteLine(D1)
    Console.WriteLine()

    For i as Integer = 1 To 10
      D2.Toss()
      Console.WriteLine(D2)
    Next i
  End Sub 

End Module

A client of class Die programmed in Visual Basic.

/user/normark/oop-csharp-1/sources/c-sharp/vb-comparison/vb-cs-cooperation/compilationCompilation and execution.