There are two ways to access the sealed class methods:
1. First way:
sealed class Class1 { static Class1 m_instance = null; public static Class1 Instance { get { if(m_instance == null) { m_instance = new Class1(); } return m_instance; } }
//Public Method public int Calculate(int a, int b) { return a + b; } }
and in the main class, you can simply get the Calculate method as
int i = Class1.Instance.Calculate(2,3) //Output i = 5;
2. Second Way:
sealed class Class1 { //Public Method public int Calculate(int a, int b) { return a + b; } }
//and in the main class, first instantiate the sealed class object Class1 objClass = new Class1();
//and then you can simply get the Calculate method as int i = objClass.Calculate(2,3)
//Output i = 5;
|
No responses found. Be the first to respond and make money from revenue sharing program.
|