Naming Conventions - Name Member Variables In .NET?

Jun 9, 2010

I am generally not one to engage in subjective arguments over matters like variable naming, code formatting, etc. So I have no intention of starting an argument here.I just came across this (old) blog post which recommends not prefixing member variable names:

[Code]...

I get it: member variables can be lower camelCase, and public properties/methods can be PascalCase. But VB.NET is case-insensitive, so you can't really give a private member the same name as a public property except with a lower case first letter.I've generally prefixed member variables with an underscore, but I've been told that's not idiomatic.

So really I'm just curious: how do you name your member variables in VB.NET? And is there a "standard" way?

I'm not asking because I believe there's a "right" way or because I particularly want to change my style, and certainly not because I have any desire to tell others they're "wrong." Like I said, I'm just curious.

View 7 Replies


ADVERTISEMENT

Variable Naming Conventions To Illustrate Variable Type And Where Variables Are Declared

Aug 24, 2009

I am looking for a good resource on variable naming conventions to illustrate variable type and where variables are declared. So I will have public variables, Private variables, private or local variables. I also may want to declare variables with the same name in different class code (i.e. in the code behind different forms). I am assuming good coding would dicatate a prefix for declaration location.

View 4 Replies

What To Use For Naming Conventions

Mar 25, 2011

What everyone uses for naming conventions?

View 3 Replies

Class Private/Public Naming Conventions?

Mar 25, 2011

I'm relatively new to .NET and am wondering how people handle naming their private variables and the public properties that access them. Like if you want to be able to just read it, but not write to it.

[Code]...

So far I've taken to putting a 'l' (for local) in front of the all the private variables so as to be able to use the full name for the property. Is there a better way around this, or do you just always have to have different names for private variable/public properties? If so, what sort of conventions do people use?

Its not a huge deal, its just a minor annoyance and I was wondering if I was missing something.

View 4 Replies

Visual Basic 6.0 To 2008 Naming Conventions?

Jan 5, 2011

iv got visual basic 6.0 and im trying to change the naming conventions because i need to change them to 2008 standards the code is for a basic book shop.im looking ofr the code for the calcualte button on a till.you enter the title,quantity and price.then it updates for extended price 15% discount and the discounted price. There is also a running total of no of books sold and the total no of dicount given in € the code is

[Code]...

View 5 Replies

What Are The Conventions For Variable Naming In .NET To Avoid Confusion Between Parameters And Properties

Oct 21, 2010

In the example below, what would you name the parameter given that it is used to initialize the property FromDate?For class constructor methods, I like to have the name of the constructor parameter variable match the name of the property which is being initialized. For example, the parameter "fromDate" is used to initialize the module level variable "_FromDate" with the statement _FromDate = fromDate. Likewise, I could have alternatively written Me.FromDate = fromDate.

Proponents of C#'s case sensitivity would probably say that using a leading lower cased letter for the param variable name, which I believe is MS convention, is an acceptable approach to distinguish it from the Property of the same name but different casing.

However, VB is not case sensitive, which I generally appreciate. In the following example, I am using a param name that matches the property name, 'fromDate," and VB refers to the local instance when there is ambiguity. However, many would probably argue that this "ambiguity" introduces the opportunity for the developer to get confused and not realize which variable is being used. For example, my intent below was to have TWO params passed in, "fromDate" and "toDate" but I accidentily ommited one and as a result, the VB.NET did not warn me of the mistake because it assumed that the statement _ToDate = ToDate was equivalent to _ToDate = Me.ToDate instead of informing me that the variable on the right side of the assignment statement was undeclared.

Public Class Period
Property FromDate As Date
Property ToDate As Date

[code]....

In my judgement, we should have a convention for prefixing all parameter variable with a prefix, but hasn't the use of prefixes been discouraged by Microsoft? For example:

Public Sub New(ByVal paramFromDate As Date, paramToDate As Date)

..or maybe it could be shortened to pFromDate, pToDate...

View 3 Replies

Correctly Naming Variables/controls?

Sep 1, 2010

Can some one please be kind enough to link me m$ naming guide lines.

View 2 Replies

Naming For Namespace / Class And Variables

Jul 7, 2009

In the code below, the namespace is called "Navigation" which I think is correct. Then I have a class called "Heading", which by definition is the direction a person/vehicle is truly pointing towards. I think that is also named correctly. In the code below, I have four things I have named:
_WhatToName1, WhatToName2, WhatToName3, and WhatToName4.
The value that gets passed in and stored is a double between 0 and 360 -- essentially the degree value from a circle. For WhatToName3 and WhatToName4, I have seen a lot of places that just use "value" as the name. Is that standard?

Namespace Navigation
Public Class Heading
Private _WhatToName1 As Double
Public Sub New(ByVal WhatToName3 As Double)
Me.WhatToName2 = WhatToName3
[Code] .....

View 18 Replies

Naming Convention For Variables In Class Constructor

Nov 26, 2010

In the past when I have written classes and constructors, I named the variables in the constructor parameter something different than what would have been stored in the actual class itself.What I do now is name them the same, and reference the internal variables with Me.varname.Here is a class I just started building.Is my naming convention incorrect? [code]

View 1 Replies

Can Have Member Variables In Interface

Aug 20, 2010

I read somewhere that interfaces can have member variables.Static final constants only, can use them without qualification in classes that implement the interface. On the other paw, these unqualified names pollute the namespace. You can use them and it is not obvious where they are coming from since the qualification is optional.

View 3 Replies

C# - Iterate Through The Member Variables Of An Object?

May 14, 2011

I'm building a litle console app that involves a control hierarchy -- there are screens, and inside of screens you can compose controls together.

You can add controls to a screen by declaring member variables (which all inherit from AresControl). The control constructor takes a simple coordinate pair. It looks like this:

Public Class IntroScreen : Inherits AresScreen
'Controls
Private LabelSelect As New LabelControl(72, 0)

[Code]....

This would result in cleaner, convention-based code. But try as I might, I can't get it to work - I can walk the member variables of a type, but I need to walk the member variables of a live object.

View 2 Replies

VS 2005 Member Variables And Events?

Oct 12, 2010

How should I handle events in this situation I have "Class1" with a "PropertyHasChanged" event.In "Class2" I've declare a Public Member Variable WithEvents of Type Class1.As well, Class2 has the Event "OtherPropertyHasChange".In a Form Class I've declare a Public Member Variable WithEvents of Type Class2.The Form Member has access to the "OtherPropertyChange" Event but not the "PropertyHasChanged" Event.Question is,how do I accesss the Events of Class1 from the Form Class?

View 6 Replies

Class Member Variables Methods And Their State

May 27, 2010

How should class member variables be used in combination with class methods?Let's say I have a class 'C' with a member variable 'someData'.I call C.getData(), which does not return a value but instead puts data in C.someData. The class that instantiated 'C' first calls C.getData and then uses the data by accessing the member variable C.someData.I call C.getData() in the class that instantiated 'C' which is a function that returns data.I myself prefer the second way. But it also depends on the situation and it's a small difference. Is it 'bad' to have class methods that depend on the classes internal state? What are the best conventions?

View 2 Replies

VS 2005 Set And Read Member Variables Of Combobox Items Object?

Jun 12, 2010

I have created a class called 'MyAddress' and in the form load event i am adding few objects of that class to the combobox. I want to know how should i set and read the values of the member variables of that selected item of the combobox. I have tried this and is working, but i am not sure whether it is the way to do

vb
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[code].....

View 2 Replies

Dynamic Variables And Picture Box / Public Member 'image' On Type 'String' Not Found?

Jun 6, 2011

I am currently making a server monitoring application that pings the server to check its uplink, so far it creates all the picture boxes and labels for each server, and then pings the server, although I have a picture that I want to change dependant on the result.

Below is the code I am currently using, the problem occurs with the objectname variable which allows dynamic coding, where i get a error, saying that "Public member 'image' on type 'String' not found".

Private Sub Ping()
Dim i As Integer
Dim objectName As System.Object
For i = 1 To count - 1

[code].....

View 4 Replies

Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

Jun 2, 2011

how do I overcome it? I have created a class and compiled into .dll This code

[Code]...

View 2 Replies

Access Of Shared Member - Constant Member - Enum Member Or Nested Type Through An Insta

Aug 13, 2009

In Visual Studio 2008, if I do this:

[Code]....

Does anyone here know how to get the above to work WITHOUT warnings being generated?

View 4 Replies

Warning 1: Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

May 31, 2010

In the following code i get a warning at line 59:Warning 1: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.and.. At line 78 I get this Warning:

Warning 2 Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

The program compiles and runs well, but i cant' undesrtand the reason for these warnings. Any Idea ?

1: Public Class Form1
2:
3: 'Form level members
4: Private objCustomers As New ArrayList

[code]....

View 5 Replies

VS 2005 Access Of Shared Member, Constant Member, Enum Member?

Apr 28, 2011

Cannot appear to be able to get this function to not have the above error.Private Function GetIncidentActions(ByVal FromAgentID As Integer, ByVal ToAgentID As Integer, ByVal incidentAction As Integer, ByVal ActionDate As Date) As String

[Code]...

View 10 Replies

Conventions For Commenting?

May 3, 2009

According to conventional programming, how is it to properly comment using the '''<summary> feature built into Visual Basic?Would I have to use the part that says

''' <param name="text">Description here
''' characters in</param>
''' <returns>The description</returns>
''' <remarks></remarks>

Here is the full commenting process; is it necessary to use all of it?

''' <summary>
''' Text here
''' </summary>

[code].....

View 2 Replies

C# - Static Checking For Framework Conventions?

Jan 27, 2012

Is there a product/project that would allow you to define conventions for say an MVC Project to statically check for naming conventions like Controller being appended on the end of classes that inherit from controller and/or enforce a certain method signature when decorating a method with an attribute.I am basically looking for a way to kind of set up some guard rails for new developers coming onto our team where we have a clear set of conventions some of which are used to wire things up dynamically through reflection. Seeing that this reflection wire-up would fail because of an incompatible signature would be a huge boon to our ramp up process.Static/Compile time checking for broken rules Ability to target methods decorated with specific attributes (via RegEx or a Wizard)Different Sets of rules based on different types of projects.(example: A set of conventions for an MVC App, a different set for a Web Forms App, and a different set for a Class Library suffixed with .BLL)?

View 1 Replies

VS 2010 Proper Variable Declaration Conventions?

Jan 4, 2011

I've been programming for many years in many languages and I've seen the variable declarations conventions change. With VS 2010 I've noticed you don't have to declare the variable type. I work alone so I can use any method I want. But, someday I may want to sell some of my code so I would like to keep my programming conventions current.

In VS 2010 which of these would be considered the best convention?

Dim srtFirstName = "Bob"
Dim strFirstName As String = "Bob"
Dim FirstName = "Bob"
Dim FirstName As String = "Bob"

View 5 Replies

Dealing With Different Coding Conventions/Styles In Visual Studio?

Sep 1, 2010

I'm working on two different projects - both in VB.NET/Visual Studio 2008 (as much as I'd like to move to 2010).

I find I'm confusing the different coding standards that I'm supposed to follow. IE - Project1 wants variables named in a Hungarian-style notation like 'iSomeValue'; the does not want a prefix. One project requires an _ prefix on private class-level variables - etc...etc...

Are there any tools I can integrate with VS 2008 that will let me easily swap between pre-defined styles and format my code for me?

View 1 Replies

Does The Assignment Operator In 1.1 Do A Member-by-member Copy Of The ObjOriginal To ObjClone

Nov 18, 2009

I'm "cloning" objects in my code. For instance: objClone = objOriginal My question is: Does the assignment operator in VB.NET 1.1 do a member-by-member copy of the objOriginal to objClone or does objClone simply point as a reference to memory referenced by objOriginal?

View 3 Replies

Access Of Shared Member, Constant Member, Enum Memberor Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated?

Jun 23, 2009

i changed a class variable to shared so i can access it in all instances of the class, but it caused an error. what is causing this, and how can i fix it?

Private
Shared img As Bitmap
Me
.img = bgImage

View 2 Replies

VS 2005 Configuring A Datasource Value Member & Display Member

Jan 6, 2011

I have 2 tables Table A & Table B Table A has the table values that I want to be populated in a datagridview control.The challenge is that column 1 in table A contains an ID(foreign key) to a name field that is a located in table B. I need the datagrid to have the first column be a combobox that displays the names(from Table B) that are already in table A via the ID's, but reference the populating values from Table B. So that when you bring down the combobox you would be choosing from Table B data but populating table A with the ID and you would see a name there instead of an ID.[code] How do I populate my DS dataset with Table B? And how can I create a link to these two tables using a bound datagridview control?

View 1 Replies

.net - The Member 'X' Was Changed To Be Inconsistent With The Association Member 'Y'?

Jan 3, 2011

I get this error if I follow these steps: Change property Y of an object (an associated entity property)
Attempt to submit changes At this point the value of Y and the value of X (the underlying key) are not in agreement -- LINQ to SQL apparently doesn't synchronize these until GetChangeSet is called.An expected error occurs due to some business logic or database level constraint during the update operation.At this point the value of Y is in agreement with X because GetChangeSet was called.Change the value of Y to Nothing (aka null).Call GetChangeSet.

The error occurs on the last step because the value of X and the original value of X (returned by GetOriginalEntityState) are different, and the new value does not agree with Y? Is that why? Is this a bug in LINQ to SQL. Must be because I don't see the same behavior if I change Y to another (non-null) value instead during step 5. What's the right way around this? I can see a few ways:

Discard the DataContext when an error occurs and leave the UI as-is. I don't like this because then optimistic cocurrency change conflicts cannot be detected. The new context doesn't have the original values in it that were populated at the same time the UI was populated, so if the UI has any stale values in it, they will cause data in the database to revert.Refresh the datacontext (OverwriteCurrent) and leave the UI as-is. I don't like this for the same reason as #1.Refresh the datacontext (OverwriteCurrent) and re-populate the UI. I don't like this because then the error message just presented to the user does not show the user the error they made and allow them to correct it. It also discards all the other changes the user may have made.When the error occurs, explicitly retrieve the key for Y that corresponds to the original value of X and reset Y, then call GetChangeSet to re-synchronize X (X is read-only or private so I can't reset it directly). This seems to work, but seems like a hack, and may require lots of code for other similar errors.

View 2 Replies

ComboBox / Binding / Display Member & Value Member

Aug 31, 2011

I know I have done this before and as I remember it should be really easy. But for some strange reason I can't do it now and I am about to jump off the building.I will make it simple:Two tables, one is just a list of products and their code.The other table: "details" has a field named product. I want to store only the code there.In the second table's entry form, I am putting a combobox. This combo box should display the list of products, their names, but depending on which one is selected, the code is what is passed to the table "details". Currently If I set the display member to product and the value member to code it still pases the product to the binded data source.

View 3 Replies

Show Display Member Based On Value Member?

Dec 6, 2010

I have a database that holds information about a particular job. One of those things is a customerID. CustomerID links to another table containing customer details. I have a combo box attached to a custom object that holds customerID as the valuemember and CustomerName as the displaymember.The JobDetails holds the customerID info. How do I set the default selection in the combobox based on the ValueMember of the combo box?

View 2 Replies

In C#, Implement An Interface Member Using A Member With A Different Name?

Apr 4, 2011

in VB.NET you implement an interface like this...

Sub SomeInterfaceMember()
Implements ISomeInterface.SomeInterfaceMember
End Sub

while in C# you do it explicitly like this (which can only be called via the interface)...

void ISomeInterface.SomeInterfaceMember(){}

or more simply, implicitly like this...void SomeInterfaceMember(){} // Note the name matches the interface member However, regarding VB, I can also do this...

Sub SomeRandomMemberName()
Implements ISomeInterface.SomeInterfaceMember
End Sub

In other words, the method that handles the implementation can have a completely different name than the interface's member name.I'm just wondering if there's something similar to this in C#. (Yes, I know I can simply do an explicit interface, then access it via another 'wrapper' member with a different name that simply delegates to it, but in VB.NET?

View 2 Replies







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