Solved

asp.net referencing a class

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

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 74

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 74

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 74

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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 …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

21 Experts available now in Live!

Get 1:1 Help Now