• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Best Pratice Newbie Question Regarding Custom Classes

I'm a newbie programmer so this might be a bit of a no-brainer for you experts, but I'm just looking for some guidence in regards to custom classes.

I created a class file called shipping.vb that lives in my App_Code folder

The Namespace in the shipping.vb file is called:

I also have a public class within that namespace called 'shipping' and a function called 'InsertShippingRecord'.

In my code behind I do something like this to instantiate my class and use that function.

Dim myShippingClass As New MyCompany.ProgramManagement.DataLayer.Shipping()

I then write the following to utilize the InsertShippingRecord function of my shipping class:

Dim insertNewShippingRecord As Int32 = myShippingClass.InsertShippingRecord()

This all works perfectly.  No problems.

My quesiton is... is this the best way to do it?  

The other night I was thinking that maybe I could import the class, similar to the way I import System.Data.SqlClient at the top of my code behind page.  It sounded like a good idea but I'm not sure.

Any feedback would be greatly appriciated.
  • 2
1 Solution
to instantiate your class you can reference it using the namespace like you have done or import the namespace so you only have to use the class name. Either is perfectly acceptable. I generally import the namespaces as I feel the code is a bit more readable if you don't have to put the namespace everytime you want to use the class.
There is no performance benefit to using either method that I know of.
I think you would be better using the LINQ or the Entity Framework.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now