Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerations in C# negative side effects of using a negative number

Tags:

c#

In a C# enumeration, are there any negative side effects of using a negative number?

I am modelling response codes and one of the codes in negative. This compiles but I want to know if there are any negative side effects to this.

public enum ResponseCodes {     InvalidServerUserPasswordCombo = -1,      // etc. } 
like image 744
AJM Avatar asked Aug 09 '12 10:08

AJM


People also ask

What are enumerations in C language?

Enumeration or Enum in C is a special kind of data type defined by the user. It consists of constant integrals or integers that are given names by a user. The use of enum in C to name the integer values makes the entire program easy to learn, understand, and maintain by the same or even different programmer.

What are enumerations used for?

An enumeration, or Enum , is a symbolic name for a set of values. Enumerations are treated as data types, and you can use them to create sets of constants for use with variables and properties.

What are enumerations explain with example?

An enumeration is used in any programming language to define a constant set of values. For example, the days of the week can be defined as an enumeration and used anywhere in the program. In C#, the enumeration is defined with the help of the keyword 'enum'.

What is enum and enumerations?

In Swift, an enum (short for enumeration) is a user-defined data type that has a fixed set of related values. We use the enum keyword to create an enum. For example, enum Season { case spring, summer, autumn, winter } Here, Season - name of the enum.


1 Answers

negative side effects of using a negative number

Clearly, with any underlying signed type, any bitwise operations are going to get "interesting" very quickly.

But using an enum as a collection of related constants can quite happily use negative values.

like image 187
Richard Avatar answered Sep 21 '22 01:09

Richard