C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Calling a function in another file Posted by LoneIguana on 29 Jun 2003 at 4:03 PM
I'm trying to call a function in another file, I tried using filename.FunctionName() but it returns the following error when I try to build it:
An object reference is required for the nonstatic field, method, or property


Report
Re: Calling a function in another file Posted by Brutes on 2 Jul 2003 at 12:25 AM
Hi

Well are you calling a function with in another class?

public class myClass
{
public string myFunction()
{
return "You called me";
}
}

public class myCallerClass
{
public static void main(string[] args)
{
myClass myObject = new myClass();
Console.Write(myObject.myFunction());
}
}

obviusly the top class can be in another file in the project.

Report
Re: Calling a function in another file Posted by yuval on 2 Jul 2003 at 9:07 AM

Hi

Suppose you have a project with a class that computes the average of 10 numbers. In a different file you already written a class "Add_numbers" that adds up numbers. What you can do here, and is, in my opinion, the logical thing to do, is to incorporate the class
"Add_numbers" into your project. Go to File->Add Existing Item and select the project that contains
the class you want. Then select the class itself.
This class in added in full to your project. Now you can access any method of this class by calling "Add_numbers.method_name". Voila.(do not forget to
make an object of this class first).

regards
yuval
Report
Re: Calling a function in another file Posted by yuval on 2 Jul 2003 at 9:21 AM

Hi

Suppose you have a project with a class that computes the average of 10 numbers. In a different file you already written a class "Add_numbers" that adds up numbers. What you can do here, and is, in my opinion, the logical thing to do, is to incorporate the class
"Add_numbers" into your project. Go to File->Add Existing Item and select the project that contains
the class you want. Then select the class itself.
This class in added in full to your project. Now you can access any method of this class by calling "Add_numbers.method_name". Voila.(do not forget to
make an object of this class first).

regards
yuval
Report
Re: Calling a function in another file Posted by LoneIguana on 2 Jul 2003 at 11:37 AM
ok, Thanks, I forgot to instantiate the class.

:
: Hi
:
: Suppose you have a project with a class that computes the average of 10 numbers. In a different file you already written a class "Add_numbers" that adds up numbers. What you can do here, and is, in my opinion, the logical thing to do, is to incorporate the class
: "Add_numbers" into your project. Go to File->Add Existing Item and select the project that contains
: the class you want. Then select the class itself.
: This class in added in full to your project. Now you can access any method of this class by calling "Add_numbers.method_name". Voila.(do not forget to
: make an object of this class first).
:
: regards
: yuval
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.