why we use static class, reasons with example
why we use static class, reasons with example.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tuhin PaulPosted Feb 28, 2023, 8:42 AM
Static classes are used in programming to create utility classes that contain static members (fields, methods, properties, or events) that can be accessed without the need to create an instance of the class. Here are some reasons why we use static classes:
Example:
Let's say you are building a game and you want to keep track of the score. You could create a static class called ScoreManager that contains a static field for the score and static methods to update and retrieve the score. Here's an example implementation:
You can then access the ScoreManager from anywhere in your code, without the need to create an instance of the class:
VulpesPosted Sep 30, 2012, 6:26 PM