Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any thoughts, though Math and Forms.Application class have all static methods Math class is static while Application is declared as sealed?

I can see that methods in Math class are kind of independent from each other, any other reason you know?
Posted

1 solution

Math is a static class so that you don't need an instance of it in order to use the methods:
C#
int max = Math.Max(12, 14);
If it wasn't static then you would have to create an instance in order do anything:
C#
Math math = new Math();
int max = math.Max(12, 14);


Application is different: it is declared as sealed so that you can't inherit from it, but it isn't static because you do want to be able to get an instance - the current application that is executing for example!
 
Share this answer
 
Comments
Mirani Ajay 26-Mar-14 5:49am    
Thanks OriginalGriff for reply.

I know the difference of static and sealed class but trying to understand why MS developers have marked Math as static and Application as sealed.

All the methods are static for both (Math & Application) so you do not need to create instance of those explicitly anyway.
OriginalGriff 26-Mar-14 6:26am    
"you do not need to create instance of those explicitly anyway"
You don't: but I'll bet the system does!
Almost certainly, Application is a Singleton class - it creates a single instance of the class to contain and control the actual application in the Application.Run method (or Run creates new instances, that's also possible) because it acts as a "bridge" between the operating system and the form class and runs the message loop, converting it to Events that .NET understands.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900