422 Chapter 19 Object-Oriented Programming
Defining a C# Class to Work with Fractions
As the final example in this chapter, Program 19.4 shows the fraction example written in
C#, a programming language developed by Microsoft, Inc. C# is one of the newer OOP
languages, and is turning out to be quite popular. It has become the language of choice
for developing applications with .NET.
Program 19.4 Working with Fractions in C#
using System;
class Fraction
{
private int numerator;
private int denominator;
public int Numerator
{
get
{
return numerator;
}
set
{
numerator = value;
}
}
public int Denominator
{
get
{
return denominator;
}
set
{
denominator = value;
}
}
public void print ()
{
Console.WriteLine("The value of the fraction is {0}/{1}",
numerator, denominator);