Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource File vs Static Class for values that will not need to be localized in C#

Tags:

c#

I overheard two of my coworkers debating this topic and I was wondering what the general thought is.

Right now in our application we use a lot of key value pairs and they are looking for the best way to implement a solution that would avoid us to remember the spelling for the key.

like image 453
Brian S. Avatar asked Apr 13 '11 21:04

Brian S.


People also ask

Why static classes Cannot be instantiated?

It is not possible to create instances of a static class. Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class.

Can we have non static method in a static class in C#?

Static class always contains static members. Non-static class may contain both static and non-static methods. Static class does not contain an instance constructor.

What is the advantage of static class in C#?

The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created. Static classes are sealed and therefore cannot be inherited. They cannot inherit from any class except Object.


1 Answers

A resource file generates static class behind the scenes to access those resources so you end up basically with the same thing. It's just that if you use a resource file and one day you decide to localize you are good to go. Of course there is no definite answer to this question. Looks subjective to me as both solutions are perfectly viable.

like image 54
Darin Dimitrov Avatar answered Oct 14 '22 12:10

Darin Dimitrov