Differences Between Enums In C#?

Jan 14, 2010

We have legacy character codes that we want to store as numbers in a new system. To increase readibility and general understanding in the code for devs making the migration, I want to do Enums like this..

[Code]...

With this setup, the code will be readable (imagine If Record.Status = Status.Open), and yet the values will be stored in the database as small numbers so it will be efficient. However... I am a VB.NET guy, but everybody wants to code in C#, so I need this sort of structure in C#.After Googling, I discovered the the general .NET equivalent of AscW is Convert.ToInt32("C"). When I try to use that statement in an enum, I get the compiler error "Constant Expression Required".

View 2 Replies


ADVERTISEMENT

Directcast & Ctype Differences With Enums?

Oct 13, 2009

Public Enum Fruit
Red_Apple = 1
Oranges
Ripe_Banana
End Enum
Private Sub InitCombosRegular()

[Code]...

Why does the Ctype work and the Directcast does not with the same syntax? Yet if I cast the selectedValue to an int before I DirectCast, then it works

View 1 Replies

Enums Error In Vb, How Is It Different From Enums In C#

Aug 3, 2011

I thought that enums in VB and C# where the same or at least very similar. Then today I stumbled across a bug in our VB code. The following VB code compiles and runs with no issues:

Enum Cars
Subaru
Volvo
End Enum

[code]....

Why does the VB version not catch the type mismatch? Are enum in VB and C# different?

View 2 Replies

C# - How To Avoid Using Enums

Feb 15, 2010

Until asking a question on here I never considered (enums) to be a "bad thing." For those out there that consider them not to be best practice, what are some approachs/patterns for avoiding their use in code?

Edit:

public Enum SomeStatus
Approved = 1
Denied = 2
Pending =3
end Enum

View 5 Replies

Enums Via Markup In .NET?

Oct 4, 2011

I have an enum and a usercontrol, both in the same assembly (a plain .NET 4 web site). In the Constants class:public Enum CrudOperations Add Edit Delete. This controls the columns in a GridView on a UserControl via a property on the UserControl

[Code]...

In C#, I've specified the columns to show with markup as Mode="Edit,Delete", but in VB.NET, this does nothing. The only way I can get anything to show is with the codebehind, but if on the containing page I use userGrid.Mode = CrudOperations.Edit And CrudOperations.Delete, I get all the columns (there's also a delete column), but userGrid.Mode = CrudOperations.Edit Or CrudOperations.Delete shows nothing.

View 1 Replies

Using Enums With INotifyPropertyChanged?

Mar 10, 2011

I have a public property, "Status" that is an enum. I have a setter method that changes the status and raises the PropertyChanged event. However, the WinForms user interface is not properly updating. I'm pretty sure it's because Status is an enum. Although I was thinking enum was a reference type but I guess it's a value type. Does INotifyPropertyChanged work the same with reference and value types?

[Code]...

View 3 Replies

'Enums.NoticeType' Is Not Defined

Nov 25, 2008

I work for a web hosting company and was handed a VB script which I apparently have to compile with some updated settings by 1 of our clients who knows less about it than I do. But when trying to compile the code I receive an error "'Enums.NoticeType' is not defined". As expected I haven't a clue. Am I missing some of the code, or do I have to add some libraries in my Visual Basic 2008 Express Edition? I have pasted the line of code below. If requested I can provide the whole script.

Code:
Public Function UpdateNotices(ByVal intNoticeID As Integer,
ByVal strNoticeTitle As String, ByVal dtDateFrom As Date, ByVal dtDateTo
As Date, ByVal intTypeID As Enums.NoticeType, ByVal boolPrimaryItem As
Boolean, ByVal boolActive As Boolean) As Int32

View 1 Replies

.net - Using VB Interfaces, Enums, Etc In C# Code?

Oct 20, 2011

I have a solution with multiple projects, some of the projects are written in VB, some in C#. I am wondering if there's a way to use interfaces and/or enums written in VB in C# classes? My C# code below doesn't compile, however I am able to see the interface in intellisense.

[Code]...

P.S It's a console/service application, not ASP.Net (where I know it's doable).UPD: Sorry guys, was missing a reference to the project with the interface. It's fixed now. I think the thing that in VB projects references are done slightly different than in C# confused me.

View 2 Replies

Asp.net - Overloading Enums And Properties In .NET?

Sep 23, 2010

I have a base class with the the following enum and property:

[Code]...

First off, how do I do this - is it by simply overloading it? And secondly will my original property pick up the new enum automatically when using the derived class or will I need to overload that too?

View 2 Replies

C# - Iterate All Public Enums?

Nov 22, 2010

We have a common component in our source which contains all the enums (approx 300!) for a very large application.Is there any way, using either C# or VB.NET, to iterate through all of them in order to perform an action on each one?

How to iterate all "public string" properties in a .net class is almost relevant but the enums I am dealing with are a mix of types.

View 5 Replies

C# - Use Flag-based .NET Enums From Lua?

Feb 16, 2012

I'm using LuaInterface for .NET to create Windows Forms objects. This works pretty good except for one thing:I want to use the Anchor property of Control to make them resize automatically. If I only set one of the Anchors (e.g. only AnchorStyles.Top), it works, but this doesn't really make sense. I have to set more than one Anchor, which is done by combining them with "bit-wise or" (or by just adding them numerically).

In VB.Net both works:
Dim myLabel As New Label()
myLabel.Anchor = AnchorStyles.Top[code]....

which is in a sense correct as "LuaInterface treats enumeration values as fields of the corresponding enumeration typ" (says LuaInterface: Scripting the .NET CLR with Lua).It is also not possible to assign the value as a number:

myLabel.Anchor = 15 -- 15 = 8 + 4 + 2 + 1 = Top+Left+Right+Bottom

This time, the error message is rather unspecific:

LuaInterface.LuaException: function

Is there a possibility to typecast the number to the correct enumeration type in Lua?

View 1 Replies

Defining C# Enums With Descriptions

Jan 27, 2010

What would the folowing VB.NET enum definition look like in C#? [code]

View 7 Replies

Enums - .NET Enumeration Representation?

Apr 16, 2010

Is it guaranteed that the numeric values for an Enum with only uninitialized values start at zero and increment by one in the order defined?

View 2 Replies

Using Enums In Project Settings?

Mar 10, 2009

I want to add a setting that uses an enum defined in form1.vb. All the research I've done suggests support for enum type settings is built-in and handled automatically by the VS IDE ... I assume this means it's as easy as defining font or color settings. However, I'm not having much. Are any of you gurus aware of how to set up an enum setting via the Project Settings UI?

View 8 Replies

VS 2008 Get Assigned Enums With OR?

Jul 22, 2010

I realize this is probably trivial, but for some reason I'm not sure how to pull it off. Say I have the following enum:

Public Enum FlagType
Docs
Email

[Code]....

How do I then at runtime determine which flags where set for flags? In this example, it should be Docs and Email.

View 19 Replies

VS 2010 : Using Strings In Enums?

Jan 9, 2012

Is there a way to use strings in Enums like the example below:

Enum myEnum
val1 = "some string 1"
val2 = "some string 2"
val3 = "some string etc"
End Enum

It seems like you can only use integers for the underlying values.

View 13 Replies

Declaring Enums Across Derived Classes

Sep 21, 2009

I am developing a program in VB.NET. I have an enum called PriceType that is declared in a super class ItemPriceBase. There are 3 classes that derive from ItemPriceBase - ItemPriceMeasured, ItemPriceNDI and ItemPriceExtraCost. The subset of PriceTypes for these classes are totally unique from each - Measured prices are 1 to 6, NDI prices are 7 to 15 and ExtraCost prices are 16 to 22.

Is there a way declare the enum in the super class and then extend the enum in each of the derived classes so that they only have access to those options, yet I can still access a property in the super class that returns an enum of PriceType?

View 3 Replies

Enums Can Be Only Declared As Integral Type?

Jan 7, 2010

i've got a custom integral type, and i want to be able to

Private Enum ENUM_Stuff As MyInteger

what i want to do: to know if there is anyway to make the above statement valid

View 7 Replies

C# - How To Group Enums Structures And Subclasses In Classes

Aug 21, 2010

I've heard bad things about overusing regions but when adding enums to my classes I put them into a #region "Enums" at the end of the class, and do the same with structures and even subclasses.

Is there a better/standard way to go about grouping such elements on classes?

(Note: this is tagged C#/VB but maybe the same situation exists for other languages, like Java)

View 1 Replies

VS 2008 Flag Enums In Property Grid

Jul 10, 2009

I have a flags enumeration property that I need to show in a property grid: [Code] In the property grid however, it only allows me to select a single value. I cannot combine the values like usual in a flags enum. How do I show something like a checked listbox in the property grid, so that the user can combine flags by checking items? A None and All item would be great but not required. [url]

But even that does not work properly. It seems to check and uncheck items arbitrarily. If you check the first and fourth item for example, the second and third items will sometimes be checked too. Yes, I realize that is supposed to happen with the TestEnum property (as that defines 'BottomRight' as 'Bottom Or Right', so that's logical), but it also happens with the SecurityFlags for example, which it shouldn't.

View 2 Replies

.net - Handling Different DbType Enums In Database-Agnostic Architecture?

Apr 17, 2012

Here's my current set-up:

Public Interface IDatabase
Function CreateParameter(name as String, dbType as <dbTypeEnumeration>)
End Interface

[Code]....

The problem here is what exactly is dbTypeEnumeration. In the example above, it's simply a placeholder to what my problem is. Since we use both Oracle and SQL Server databases, the DbTypes are different depending on the database being used. For Oracle, the OracleClient object has its own OracleDbType enumeration with types. SQL Server also has its own enumeration.

My question is: is it possible to show those database-specific enumerations depending on which repository is injected into the DatabaseService constructor? If not, what's the best way to go about this? I want to separate the two databases, share logic, and allow for future development, ala the interface as a code contract for that development.

View 2 Replies

SQL - Store Enums At Database Level Or In Application Logic?

Jan 19, 2010

I have a table, lets call it Objects. It has a predefined set of records looking like this:
ObjectId ObjectName
1 Salmon
2 Trout
3 Seabass
4 Shark
Etc..

So, this I would like to implement somehow as an enum. But what's the best way, implement it in the database creating tables for it or in the application logic in an CommonEnums codebehind file etc?

View 2 Replies

Differences Between 32 And 64-bit

Aug 22, 2010

What are the differences between 32 and 64-bit .NET (4) applications?Often 32-bit applications have problems running on 64-bit machines and conversely. I know I can declare an integer as int32 and int64 (certainly int64 on 32-bit systems make problems). Are there other differences between programming an 32 OR 64-bit or a both 32 AND 64-bit compatible application?

View 2 Replies

Differences Between VB And C#?

Aug 10, 2010

Would like to build an application and was wondering why someone would choose one language over another.Also is one language used more for a particular type of programming then another (For example, is VB used more for business or Windows development then for web development ?)

View 1 Replies

What Are The Differences Between .net And VB5

Aug 14, 2009

I am currently learning visual basic 5 on my home computer. I was wondering if someone could tell me what the major differences are between Visual basic 5 and the latest/new editions of VB.

View 3 Replies

Differences Between Vb6's Interface And .net?

Dec 13, 2011

in order for me to get help on me and my programming partners vb6 rpg, I have to upgrade the project to the vb.net platform, and I am worried that the IDE interface that is used to program the vb side of the rpg is different, so I am wanting to ask any of you if there are any significant changes to the IDE or if it is relatively the same as it was in vb6... I am also hoping that someone here can also help me to see what is wrong with my load/save function... I now thought of something to try to see if that is the issue or not, but the code is still vb6 code, the only difference will be that the program will be upgraded to the .net platform, so if that changes anything in the code, then I am not aware of this as of yet, because I am still downloading the visual studios 2010 express iso right now... so I do not know for sure yet what will be changed.

View 3 Replies

Final Differences In VB?

Dec 18, 2011

Does anyone know how to implement in VB an algorithm for final differences that changes the network (the matrix) during the computation (decrease its dimensions)?

View 1 Replies

Generated IL Differences For VB And C#

Aug 26, 2011

Today I was playing around with Entity Framework and I've read that the generated IL for C# was different than VB.NET for the following code:

[code]...

As it seems the VB.NET version of this code will contact the database every time the code is executed while the C# version will retrieve the entities from the cache when the code is executed multiple times.Why would they make both languages behave in such a different manner?It was my misconception that both languages just differed in syntax and had almost exactly the same generated IL.Are there any more examples where both languages generated such different IL?

View 2 Replies

Main Differences Between VB And C#

Jan 17, 2011

what can C# do that VB.Net can't ? VB.net vs C#.net

main differences between visual basic and C# as well as the pros and cons between the two?

View 1 Replies

.net - Compare Text And Get Differences?

Jul 18, 2011

Well i want to compare 2 strings (version one and version two) and get the differences in a format that i can convert to html on my own, like you can view how a post was edited here on stack*overflow* or like svn tracks differences between revisions....

It must be full managed code library.

Like this JavaScript but i need to do it on the server-side..

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved