Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the c# equivalent of public final static in java

In Java I can write:

public final static MyClass foo = new MyClass("foo"); 

Is there any equivalent in C#?

like image 880
peter.murray.rust Avatar asked Jul 25 '09 09:07

peter.murray.rust


People also ask

What is C language in simple words?

What Does C Programming Language (C) Mean? C is a high-level and general-purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software, C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System in the early 1970s.

What is C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C for computer?

C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on. C programming is an excellent language to learn to program for beginners.


1 Answers

The closest thing (not exactly the same, final has other meanings too) for Java final fields I can think of is readonly:

public static readonly MyClass field = new MyClass("foo"); 

If you have a primitive type (string, int, boolean), you may want to use const instead.

public const string MAGIC_STRING = "Foo"; 
like image 51
mmx Avatar answered Sep 28 '22 05:09

mmx