Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

Class hierachy and methods

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom Machado - 20 Aug 2006 20:39 GMT
Hello,

I am working on a project and have become a little confused on how to
call methods from another class. Before I explain, here is an example:

class 0
{
  main()
  {
     class 1 = new class1();
  }
}

class 1
{
  class1()
 {
    /*
     now I want to call a method from class 0 (i.e.
class0.getVariable()) do I need to make a new instance or what since
this class already being called by class 0?
   */
 }

}

Any idea? Also, class0 is a windows form and class1 is not, so calling
it again doesnt really make sense to me...

Thank you!

Tom
Arne Vajhøj - 20 Aug 2006 20:47 GMT
> I am working on a project and have become a little confused on how to
> call methods from another class. Before I explain, here is an example:
[quoted text clipped - 22 lines]
> Any idea? Also, class0 is a windows form and class1 is not, so calling
> it again doesnt really make sense to me...

The second class need a reference to the first class.

If the first class A do:

B o = new B(this);

and the second class B looks like:

public class B
{
    private A a;
    public B(A a)
    {
       this.a = a;
    }
    ...
}

then other metods in B can call:

a.somemethod();

Arne
tomb - 20 Aug 2006 20:52 GMT
You can pass a reference to class0 to the constructor of class1, then
call class0 functions through the reference object.

class 1 = new class1(this);

T

>Hello,
>
[quoted text clipped - 30 lines]
>
>  
Tom Machado - 20 Aug 2006 21:43 GMT
Perfect! Thank you for your help!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.