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


ADVERTISEMENT

Interacting Classes With SubClasses?

Mar 17, 2009

I have a project in Visual Basic 2008 where there is a Main Class and couple of classes inside the Main Class. I want to be able to share variables/objects within the Main Class and SubClasses while those vars/object are instanced.

Ex:

Code:
Public Class clsMain
Public t as New clsSub1

[Code].....

So, can i make var1 be in separate instances per clsMain in the memory while being able to access the var1 in clsSub1?

View 2 Replies

VS 2008 Casting Subclasses, Base Classes?

Jun 26, 2010

I am a VB6 programmer learning VB.Net and am having trouble with the following concept.

[Code]...

View 4 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

Difference Between Classes And Structures

Oct 23, 2010

I know that Structures are value types and classes are reference type, i know that since structures are stored in stack they are faster to use i also understands that structures can not use the Inheritance concept but still in most examples i see i always see that the authors use classes when building something like BBL library, if structures is light-weight compare to classes and i don't need it to be inherited should i use structure instead of class?is there a rule of when to use class and when to use structure ?

View 2 Replies

Structures Versus Classes?

Feb 3, 2011

I've been programming a custom structure to use in my program for a while now and I am debating whether I should switch over to using a class instead. Reason being is because I've read from a few sources that structures should be kept for simple storage of primitive types. However, I am using my structure to store a few integers and a few custom classes of my own.I haven't noticed any slowdowns or performance issues but I do know that I have to update the actual variables in the structures since they are value types and not reference types.

View 5 Replies

VS 2010 - Classes Vs Structures?

Dec 11, 2011

For the time being I have been using a Structure to store "people" (their name, gender, age, etc...), because I really love to refer to something like Mike.name or Caroline.age, so I could simply put Caroline.age += 1 anywhere in the code and here you go, Caroline is one year older. No more simpler.But because of how inflexible (compared to Classes) Structures appear to be, when I needed to iterate through all the instances I was forced to use a list or dictionary so I could use a FOR EACH ... NEXT block. That was resolved by you people in the previous post, but I'm having the problem that I couldn't use the elements of the list to change the original instance of the Structure proper... I mean, if I code something like this...

For Each thisperson As Person In peoplelist
If thisperson.name = person_selected Then
'person_selected is the SelectedItem.ToString of a listbox[code]....

Well, I thought that thisperson.teamleader and Mike.teamleader were going to be equivalent (when the IF statement was true, that is) but that doesn't appear to be the case. So right now I'm really hating Structures...But when I look into Classes... well, they have more flexibility, yes. You could construct a FOR EACH block without any other trick like the "on-top" list, and that it's very useful indeed, but (a big "but" IMHO) I lose that NICE feature that makes possible to write the name of one of them instances like Mike.age or Caroline. kills

I mean, if I wanted to add a year to Mike, well... there is no "Mike" in the first place. A "Mike" string could be a property for the class, but I cannot (or know) magically refer to him with the ease of a Structure, so when I want something so simple as Mike.age +=1 ...well, with a Class I'm simply clueless to how locate him and change ANOTHER property of him.I suppose I am doing something very wrong, because I cannot believe VBasic could force on you those two extreme philosophies...:

Classes = +flexibility -usability ???

Structures = -flexibility +usability ???

What I want to do is SO simple that I cannot believe I need to choose between the two.

View 25 Replies

Can Still Get Safearray And Bitmap STRUCTURES (not Classes) In .NET 2005

Sep 27, 2009

I have tried this question several times, sometimes a little in the face of MS VB teams but with no constructive answers. Perhaps with too much rant. I suspect that VB.NET does not allow me to do what I can easly do in VB5.0. The VB team should easily be able to supply the information I need, but have not yet answered the questions. I want to do a lot of work on very large bitmaps (20 Mp or more; 80Mb or more ARGB) using arrays for access. This I used to do in VB5.0 using the SAFEARRAY and BITMAP STRUCTURES. NOT the corresponding .NET CLASSES. But I now need to use an SDK requiring .NET. However, through lack of wisdom, the VB team dropped 5 critical resources on the move to VB.NET - VarPtr, VarPtrArray, the 2 structures and CopyMemory. The SAFEARRAY CLASS seems to lack a set method for array data and the BITMAP CLASS seems to lack both get and set methods for data. On building a .NET solution using VB.NET, c#.NET and C++.NET projects I could not locate the set and get methods. Interop could not upgrade my VB5.0 to VB2005 - presumably on account of these 5 problems. I was surprised that even C++ suffered too. .NET hurts. So, first off, two critcal simple questions: A) Bearing in mind that much of the .NET is tinsel-wrapped APIs, does a pointer to an array still point to a defining SAFEARRAY STRUCTURE of the original format (NOT of course to a first element of an array). If that is so, I am lucky for I can then fill and use (perhaps) my own SAFEARRAY STRUCTURE by memory manipulation in C++. B) If the same applies to a bitmap pointer I can then perhaps do the same with BITMAP STRUCTURES. If that can be done I can hopefully work in a .NET solution containing C++ (for the pointer and mmory work) and VB2005 (for the rest of the work). I can then 1) in VB define two empty byte-arrays GLOBAL in VB.NET- Pic1() and Pic2(). They do not need to be dimensioned. SAFE FROM GC 2) in VB define two GLOBAL SAFEARRAYS to match the arrays, one with one and another with 2 dims matching the bitmap in size. SAFE FROM GC 3) move ByRef the 4 objects to VC++. STILL SAFE FROM GC, LEFT EXACTLY WHERE THEY WERE. 3) copy the BITMAP data pointers to the data pointers of the SAFEARRAYS. DOES NOT MOVE ANYTHING. 4) copy the addresses of the SAFEARRAYS to the corresponding arrays STILL DOES NOT MOVE ANYTHING, BUT JOB DONE. And then I will be able to process the images in seconds rather than minutes after moving only 4 4-byte numbers. I would welcome alternative sequences, provided they DO NOT involve put and set pixels or array elements on the trivial side and do not involve moving 80Mb of image data between "safe" and "unsafe" memory on the Herculian side. Else, as the Pic() ans Safearrays MUST point somehow to structures, WHAT EXACTLY ARE THEY, AND WHERE? I want to access them. If I can't overcome these 5 silly MS blunders I'll just have to build two uncoupled projects - one in VB5.0 and the other in VB/VC++ .NET. I'm not going to get involved myself with tinsel and gladwrap workarounds.

View 4 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

(2005) Arrays Of Structures Within Structures?

Jan 20, 2009

I have a structure called 'Scheme' and in my program I want (ideally) an ArrayList of 'Schemes' (so i can add, remove schemes etc.). However, within the 'Scheme' structure, I want to have an ArrayList of 'Item''Item' is another structure. Are there any solutions out there for iterating through these arrays quite easily?

How can I easily add multiple Items to a Scheme and mutliple Schemes to my Scheme array. Code is below. When I try to add Items to a Scheme, I get the 'Object not set to a reference of an object, try the 'New' keyword', but you cannot declare 'New' keywork within a structure.

[Code]...

View 4 Replies

.net - Shared Variables Among Subclasses?

Jan 18, 2011

I have a problem with inherited classes. Have a look at the following VB.NET 2.0 / VS 2005 code:

MustInherit Class templateclass
Public Shared x As String
End Class
Class child1

[code]....

The templateclass has a shared variable x which is of course inherited by the child classes. But I wonder that all child classes share only one x! Until now I thought that shared variables are only shared among the instances of a class, not among all childs. This is very annoying because I have a base class which I need in two slightly different versions and they should not "share the shared" variables. And because the classes have a lot of shared variables, shadowing each in the childs would be very..

View 1 Replies

.NET Generic Constraints And Subclasses?

Sep 17, 2010

Consider the following extension method:

<Extension()> _
Public Function Satisfies(Of T)(ByVal subject As T, ByVal specification As ISpecification(Of T)) As Boolean
Return specification.IsSatisfiedBy(subject)
End Function

This works as expected if subject is the exact class being operated on by the specification. However, if the specification is examining the super-class of T, this extension will not work unless subject is explicitly cast to the super-class. Is there a way I can avoid this? So far, the best I've been able to come up with is:

[Code]...

Since I (apparently) can't get this to work exactly as I'd like in VB.NET due to limitations in the language itself, is my second attempt the safest/most efficient way to do this?

View 2 Replies

XML Serialization - Objects With Different Subclasses

Oct 11, 2011

I'm want to serialize a list(of Animal) of objects with different subclasses of type "their own type" but getting nowhere as exceptions doesn't give out any useful information. I've set up the serializer method which which serializes individual sublass objects if I declare them with their own type but not if I declared them as a derived (Animal).

Code is below:
Public Sub XMLPersistAnimalList(ByVal filePath As String)
Dim serializer As New XMLSerialization(m_animalList, filePath)
serializer.Serialize(Of List(Of Animal))(filePath, m_animalList) '------doesn't work!
[Code] ......

View 4 Replies

Control The Element Names Of Serialized Subclasses?

Jul 5, 2011

Let's say I have the following class structure (simplified from my real-world problem):

Public Class PC_People_Container
Private _people_list As New List(Of PL_Person)
Public Sub New()[code].....

If I were to serialize this, I'd get the default assigned node names in my XML. That means my root is named PC_People_Container and each person in the list is marked up as PL_Person. I know I can change the root node using <XmlRoot(ElementName :="PeopleContainer")>. The trouble is doing that for the subclasses. I can't use the <XmlRoot> tag on PL_Person class because there can't be two root elements, and IntelliSense throws a fit when I try to use the <XmlElement> tag on a class like I would on a property. Is it even possible to control what those subclasses are named when they're serialized as child nodes?

View 1 Replies

Structures And Arrays Of Structures?

Jun 2, 2010

I read in the Book "Mastering Microsoft Visual Basic 2008" about "User-Defined data types".The example given is creating a Structure as follows.I wanted to check that so I wrote all the code given; I used a TextBox and a Button for this.(I didn't include the "CheckDate" here; that is in the book)

Structure CheckRecord
Dim CheckNumber As Integer

[code]....

The problem is this does work.What I get is "00000". and I found out that the "Checks(4)" Array does hold any value ie: on keeping the cursor over that, it shows "CheckAmount 0.0, CheckNumber 0 , CheckPaidTo Nothing ".

View 1 Replies

See If Current User's Group Name Matches A Specified Group Name Using Active Directory Roles And SID's?

May 3, 2011

I'm trying to match up a specific group name and see if it exists for the currently logged in user using Active Directory roles. If the Group Name exists for the Current User, I want that group name to be displayed in a drop down list. Example: If current user is in BIG Group, display BIG in drop down list.Problem: All I am getting is SIDs and I'm not able to get anything to match up to the group name and nothing will show up in the drop down list.I also get the following Error:Error: Object variable or WIth block variable not set.How do I fix this?? here is the code I am using:

Private Sub GetMarketingCompanies()
' code to populate marketing company drop down list based on the current logged in users active directory group that

[code].....

View 3 Replies

Enumerate If An Active Directory Group's Member Is User Or Another Group

Jan 31, 2011

Enumerate if an Active Directory group's member is user or another group

View 1 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

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

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

Use LINQ To Filter Collection Of Nested Classes To Yield Dictionary Of Unique Properties Of Those Classes?

Jan 23, 2012

I have two classes, one nested in the other. [code]Neither "Name" or "ID" are unique between operations and records.I wish to construct a dictionary using LINQ = Dictionary(Of String, Of List(Of Integer), whereby the keys are uniqe examples of Names in my collection and the values are the collective set of distinct IDs that are associated with those names.

View 2 Replies

VS 2010 Structure Classes So That The User Interfaces Though A Single Class While The Supporting Classes Are Hidden From Their View?

Jun 13, 2012

How can I structure my classes so that the user interfaces though a single class while the supporting classes are hidden from their view? I think its best understood in an example:

Public Class MyInterface
Public Economic as EconomicClass
Public Sub New()
MyBase.New()

[code].....

So you might ask why am I even separating them? It's strictly for others who will be working with this interface. I need to funnel them though a logical structure:

interface.Economic.MyMethod
interface.Currency.MyMethod
etc

This way everything is already handled for them in the background and they only need to run the method they need. I don't know if I can have it both ways in VB.NET.

View 23 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







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