tagged [constants]

Namespace constant in C#

Namespace constant in C# Is there any way to define a constant for an entire namespace, rather than just within a class? For example: Gives a compile error as follows: Expected class, delegate, enum, ...

12 May at 14:46

How can I get a resource content from a static context?

How can I get a resource content from a static context? I want to read strings from an `xml` file before I do much of anything else like `setText` on widgets, so how can I do that without an activity ...

Declaring a hex constant in VB.NET

Declaring a hex constant in VB.NET How can I convert the following C# hexadecimal into a [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) hexadecimal? I tried the following, but it doesn't wor...

8 Jan at 17:12

Type-inferring a constant in C#

Type-inferring a constant in C# In C#, the following type-inference works: But why can't the type be inferred when the variable is a constant? The following throws a compile-time exception: ``` const ...

24 Jan at 19:33

Is there a runtime benefit to using const local variables?

Is there a runtime benefit to using const local variables? Outside of the ensuring that they cannot be changed (to the tune of a compiler error), does the JIT make any optimisations for const locals? ...

10 Nov at 13:26

What is the point of a constant in C#

What is the point of a constant in C# Can anyone tell what is the point of a constant in C#? For example, what is the advantage of doing as opposed to I get that constants can't be changed, but then w...

31 Mar at 00:1

Static Constants in C#

Static Constants in C# I have this code; Visual Studio tells me: `The constant 'Rapido.Constants.FrameworkName' cannot be marked static` How can I make this constant available from other classes witho...

9 May at 03:21

Can I declare constant integers with a thousands separator in C#?

Can I declare constant integers with a thousands separator in C#? The [Cobra](http://cobra-language.com) programming language has a useful feature where you can use underscores in numeric literals to ...

22 Jan at 10:56

How to have abstract and overriding constants in C#?

How to have abstract and overriding constants in C#? My code below won't compile. What am i doing wrong? I'm basically trying to have a public constant that is overridden in the base class. Thanks as ...

9 Mar at 05:23

variable that can't be modified

variable that can't be modified Does C# allow a variable that can't be modified? It's like a `const`, but instead of having to assign it a value at declaration, the variable does not have any default ...

7 Sep at 08:42

Why is there no Constant feature in Java?

Why is there no Constant feature in Java? I was trying to identify the reason behind constants in Java I have learned that Java allows us to declare constants by using `final` keyword. My question is ...

7 Mar at 02:53

When, if ever, should we use const?

When, if ever, should we use const? `Const` is baked into the client code. `Readonly` isn't. But `const` is faster. May be only slightly though. The question is, is there ever any scenario where you s...

17 Feb at 04:46

What is the difference between const int*, const int * const, and int const *?

What is the difference between const int*, const int * const, and int const *? I always mess up how to use `const int*`, `const int * const`, and `int const *` correctly. Is there a set of rules defin...

19 Dec at 19:14

Why can't I have "public static const string S = "stuff"; in my Class?

Why can't I have "public static const string S = "stuff"; in my Class? When trying to compile my class I get an error: > The constant `'NamespaceName.ClassName.CONST_NAME'` cannot be marked static. a...

30 Oct at 08:35

Receiving 'Expression being assigned must be constant' when it is

Receiving 'Expression being assigned must be constant' when it is Is there a way to use something like this: I think it would be more readable and less error prone than using something like: Are there...

21 Sep at 12:54

How to declare a constant in Java?

How to declare a constant in Java? We always write: Question: 1. Is static final the only way to declare a constant in a class? 2. If I write public final int A = 0; instead, is A still a constant or...

8 Apr at 05:0

Why can constants be implicitly converted while static readonly fields cannot?

Why can constants be implicitly converted while static readonly fields cannot? Given the below code, I wonder why `referenceValue = ConstantInt;` is valid while `referenceValue = StaticInt;` fails to ...

22 Jan at 10:24

Const array of strings

Const array of strings > [Declare a Const Array](https://stackoverflow.com/questions/5142349/declare-a-const-array) I need an array of const strings in the class. Something like But this code causes...

23 May at 10:31

Difference between static and const variables

Difference between static and const variables what is the difference between "static" and "const" when it comes to declare global variables; which one is better (considering that these variables wont ...

28 May at 20:16

Is there a difference between private const and private readonly variables in C#?

Is there a difference between private const and private readonly variables in C#? Is there a difference between having a `private const` variable or a `private static readonly` variable in C# (other t...

4 Jan at 09:30

How to initialize const member variable in a class?

How to initialize const member variable in a class? ``` #include using namespace std; class T1 { const int t = 100; public: T1() { cout

12 Jun at 16:25

Sharing constants across languages

Sharing constants across languages I have a long list of constants that I need access to in several projects which are in different languages(Verilog, C, C++ and C#). Rather than repeating them in eac...

23 Aug at 18:1

Why Is `Export Default Const` invalid?

Why Is `Export Default Const` invalid? I see that the following is fine: However, this is incorrect: Yet this is fine: Can this be explained please why `const`

Differences Between vbLf, vbCrLf & vbCr Constants

Differences Between vbLf, vbCrLf & vbCr Constants I used constants like `vbLf` , `vbCrLf` & `vbCr` in a ; it produces same output in a MsgBox (Text "Hai" appears in a first paragraph and a word "Welco...

14 Sep at 08:47

Using nested classes for constants?

Using nested classes for constants? What's wrong with using nested classes to group constants? Like so: ``` public static class Constants { public static class CategoryA { public const string ...