As @ReedCopsey has already pointed out, the way to extend the functionality of a sealed class is with an Extension Method. Here is one that will do what you are asking:
public sealed class MyClass
{
int a; int b;
int Add (int x, int y)
{
return x + y;
}
}
public static class MyClassExtensions
{
public static decimal Average(this MyClass value, int x, int y)
{
return (x + y)/2M;
}
}
Usage:
var myClass = new MyClass();
// returns 15
var avg = myClass.Average(10, 20);
EDIT As requested, here is the all the code. Create a new Console Application in Visual Studio, replace all the code in the Program.cs file with the code below and run.
using System;
namespace ConsoleApplication1
{
public sealed class MyClass
{
public int X { get; private set; }
public int Y { get; private set; }
public MyClass(int x, int y)
{
this.X = x;
this.Y = y;
}
int Add()
{
return this.X + this.Y;
}
}
public static class MyClassExtensions
{
public static decimal Average(this MyClass value)
{
return (value.X + value.Y) / 2M;
}
}
class Program
{
static void Main(string[] args)
{
var myClass = new MyClass(10, 20);
var avg = myClass.Average();
Console.WriteLine(avg);
Console.ReadLine();
}
}
}