473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

so many simple questions - how can I call the functions of my 1st cs file in 2nd cs file

I defined some functions in one .cs file, i.e. ShowHelp(). Now I need use
them in my other cs files. How to do that?
This is a WinForm application.
Thanks.
Nov 16 '05 #1
2 925
Jessie,
Make sure your ShowHelp() method is declared as public, then just
instantiate the object in your other class and call the method. Since the
classes are in different .cs files, just make sure that you either put a
"using" namespace statement at the top of the other class, or fully qualify
the namespace of the class you want to instantiate.

example:

public class Class1
{
public void ShowHelp()
{
//code
}
}

public class Class2
{
private void CallOtherMethod()
{
Class1 myObject = new Class1();
myObject.ShowHelp();
}
}

--

Lateralus [MCAD]
"Jessie" <je**********@hotmail.com> wrote in message
news:LX*************@news04.bloor.is.net.cable.rog ers.com...
I defined some functions in one .cs file, i.e. ShowHelp(). Now I need use
them in my other cs files. How to do that?
This is a WinForm application.
Thanks.

Nov 16 '05 #2
Hi. I assume you have a class "Class1" with a ShowHelp() Method. To be able
to use it in another class "Class2" in the other cs file you need to declare
ShowHelp() as public:

---This is file class1.cs, for example
public class Class1
{
public void ShowHelp()
{
}
}

---This would be class2.cs, for example
public class Class2
{
Class1 cls1 = new Class1();
public void SomeMethod()
{
cls1.ShowHelp();
}
}

Hope this simple example helps.
"Jessie" <je**********@hotmail.com> wrote in message
news:LX*************@news04.bloor.is.net.cable.rog ers.com...
I defined some functions in one .cs file, i.e. ShowHelp(). Now I need use
them in my other cs files. How to do that?
This is a WinForm application.
Thanks.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
71
by: cj | last post by:
Dear friends, I have one more questions for everyone in the newsgroup: I am preparing for an interview on UNIX/C++. Could you please identify some of the most important questions which might be...
4
by: Shane | last post by:
Thanks in advance for your help. I have created several classes that each have their own member functions that allow them to print the data stored int their respective classes. In other words,...
21
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
9
by: questions? | last post by:
if I use malloc() in a function to allocate a space for my array of structures. I didn't free() them anywhere in the program. I found that I can still use that space after I come back to...
6
by: Robbie Hatley | last post by:
I'm maintaining a software project with 134 C++ files, some of them huge (as much as 10,000 lines each), and very few prototypes. The author's attitude towards prototypes was like this: ...
1
by: Mukesh_Singh_Nick | last post by:
I am learning classic ASP 3.0. Below are my questions: 1. Do we have to include (<!-- #include FILE="global.asa" -->) the global.asa file into every .asp page? I am doing the examples in Windows...
4
by: Viviana Vc | last post by:
Hi all, I've read the WindowsVistaUACDevReqs.doc documentation and I have done different small tests on Vista to understand the bahaviour and now I have a few questions. 1) If I create a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.