Solved

asp.net referencing a class

Posted on 2011-09-13
10
310 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short film showing how OnPage and Connectwise integration works.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now