Solved

asp.net referencing a class

Posted on 2011-09-13
10
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 104
ASP.NET Calendar Control 5 25
SSIS GUID Variable 2 35
Web page design problem 3 16
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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