In Java I can write:
public final static MyClass foo = new MyClass("foo");
Is there any equivalent in C#?
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.
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 ...
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.
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With