Solved

asp.net referencing a class

Posted on 2011-09-13
10
311 Views
Last Modified: 2012-05-12
Hi,

I am building an desktop app in C#, So I have a form called FORM1.cs and in the same solution I have a class file called RequiredColumns.cs.

I want to be able to reference/call the class from the RequiredColumns.cs file in FORM1.cs

The code in the  RequiredColumns.cs

Shown below

Please help

Thanks,

R8VI
Public class PropertyInfo 
{
    public PropertyInfo()
    { 
    }

    int iPropertyID;
    string sAddress; 


    public PropertyInfo (int iPropertyID, string sAddress)
    {
      this.iPropertyID = iPropertyID; 
      this.sAddress = sAddress;
     }


}

Open in new window

0
Comment
Question by:R8VI
  • 4
  • 4
  • 2
10 Comments
 
LVL 5

Expert Comment

by:Rainverse
ID: 36529849
PropertyInfo objPropInfo = new PropertyInfo();
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36529850
I want to be able to reference/call the class from the RequiredColumns.cs file in FORM1.cs
While this is entirely possible, I'd just like to confirm that you indeed want to make use of the code found in Form1.cs. You are aware that you won't be able to actually display the form via ASP.NET to an end-user, right?
0
 

Author Comment

by:R8VI
ID: 36529896
HI Rainverse

I did what you are suggesting and it says the type or namespace name PropertyInfo could not be found are you missing a using directive or an assembley reference

Hi Kaufmed yes I am aware of that

Please help

Thanks,

r8VI
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 5

Expert Comment

by:Rainverse
ID: 36529928
Well then I guess you need a using PropertyInfo; statement at the top, though I'm not quite sure why.

-MJC
0
 

Author Comment

by:R8VI
ID: 36529945
I am confused what do you mean at the top
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36529953
@Rainverse
Well then I guess you need a using PropertyInfo; statement at the top,
You don't using a class--at least now how it's implied in that statement. You using a namespace!

@R8VI
Is there a namespace declaration surrounding the PropertyInfo class? If so, what is the name of said namespace?
0
 

Author Comment

by:R8VI
ID: 36529967
Hi kaufmed,

There isnt a namespace surrounding the class at the moment

Thanks,

r8VI

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36530063
It's generally a good idea to have a namespace. In the interim, while you decide whether or not to have one, try declaring your variable like this:

global::PropertyInfo objPropInfo = new global::PropertyInfo();

Open in new window

0
 

Author Comment

by:R8VI
ID: 36530170
Hi would it be easier or better if I put a namespace ,
And if I did then how would I still reference the class ?

Thanks,

R8vi
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36530278
Hi would it be easier or better if I put a namespace ,
Easy/hard doesn't really come into play. "Better"? I suppose many would say yes. I would agree.

Using a namespace is a way to structure your code into a logical layout. It also helps avoid naming conflicts when two developers (or even one developer) use the same name for two different class definitions. Take for example the following two classes:

public class Record
{
    public int Speed { get; set; }
    public string BandName { get; set; }
    public int SongCount { get; set; }
}

Open in new window


public class Record
{
    public int BatchId { get; set; }
    public string ClientName { get; set; }
}

Open in new window


Now you might infer from the names of the properties what each class is supposed to represent. Overlooking that, what if I needed to use both of these classes in the same code:

public class RecordCompany
{
    public Record CurrentAlbum { get; set; }
    public Record Producer { get; set; }
}

Open in new window


In lines 3 and 4 above, how does the compiler know which Record to apply to each line? A simple way to accommodate this scenario is to use namespaces:

namespace Audio
{
    public class Record
    {
        public int Speed { get; set; }
        public string BandName { get; set; }
        public int SongCount { get; set; }
    }
}

Open in new window


namespace Accounting
{
    public class Record
    {
        public int BatchId { get; set; }
        public string ClientName { get; set; }
    }
}

Open in new window


Now, the earlier code can be adjusted as such:

public class RecordCompany
{
    public Audio.Record CurrentAlbum { get; set; }
    public Accounting.Record Producer { get; set; }
}

Open in new window


Now you should be able to see to which Record you were referring in each line.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question