C# Program using aggregation


In this program, You will learn how to implement aggregation in C#.


Aggregation in C#

represents a HAS-A relationship.

"Alternative of Inheritance."

Example: How to implement aggregation in C#

using System;
public class A
{
	public int x = 10;
}

public class B
{
	A obj;

	void display()
	{
		obj = new A();
		Console.WriteLine("x value is:" + obj.x);
	}

	public static void Main(string[] args)
	{
		B t1 = new B();
		t1.display();
	}
}

Output:

x value is:10