Solved

asp.net referencing a class

Posted on 2011-09-13
10
312 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON  parse help 7 40
looking for an ASP.net report designer 4 8
Code enhancement 4 20
ASP.NET MVC - Views 3 17
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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