473,322 Members | 1,714 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,322 software developers and data experts.

Calling function from another .cs file

I have a form1.cs file where I am trying to call a sorting
function from a SortingAlgorithms.cs file. They are part
of the same solution, but even when I make the
SelectionSort algorithm public static, it does not appear
in the intellisense, not does it let me call it. I tried
even instantiating an object of type Sorts, the name of my
class, but that did not help. Also, I added the namespace
for the Sorts class to the top of my form1.cs class.

How do I call the SelectionSort from class Sorts.

Following is some code snippets:

In form1.cs class:

using DSM.SortingAlgorithms; //at top of form1.cs

In private void Form1_Load(params here)
{
//define A[10] here

Sorts s = new Sorts();

s.SelectionSort(A) // does not work
.SelectionSort(A) // does not work
}

In SortingAlgorithm.cs module
namespace DSM.SortingAlgorithms
{
Sorts
{
public static void SelectionSort(int [] A)
{
//do stuff here
}

//other algorithms
};
}
Nov 15 '05 #1
4 8986
Try DSM.SortingAlgorithms.Sorts.SelectionSort(A) or simply
Sorts.SelectionSort(A) if using the DSM.SortingAlgorithms namespace. You
don't access static methods by instantiating the object.

"David Miller" <da**********@cinfin.com> wrote in message
news:06****************************@phx.gbl...
I have a form1.cs file where I am trying to call a sorting
function from a SortingAlgorithms.cs file. They are part
of the same solution, but even when I make the
SelectionSort algorithm public static, it does not appear
in the intellisense, not does it let me call it. I tried
even instantiating an object of type Sorts, the name of my
class, but that did not help. Also, I added the namespace
for the Sorts class to the top of my form1.cs class.

How do I call the SelectionSort from class Sorts.

Following is some code snippets:

In form1.cs class:

using DSM.SortingAlgorithms; //at top of form1.cs

In private void Form1_Load(params here)
{
//define A[10] here

Sorts s = new Sorts();

s.SelectionSort(A) // does not work
.SelectionSort(A) // does not work
}

In SortingAlgorithm.cs module
namespace DSM.SortingAlgorithms
{
Sorts
{
public static void SelectionSort(int [] A)
{
//do stuff here
}

//other algorithms
};
}

Nov 15 '05 #2
that worked.

Is there any way to shorten that?

David
-----Original Message-----
Try DSM.SortingAlgorithms.Sorts.SelectionSort(A) or simply
Sorts.SelectionSort(A) if using the DSM.SortingAlgorithms namespace. Youdon't access static methods by instantiating the object.

"David Miller" <da**********@cinfin.com> wrote in message
news:06****************************@phx.gbl...
I have a form1.cs file where I am trying to call a sorting function from a SortingAlgorithms.cs file. They are part of the same solution, but even when I make the
SelectionSort algorithm public static, it does not appear in the intellisense, not does it let me call it. I tried even instantiating an object of type Sorts, the name of my class, but that did not help. Also, I added the namespace for the Sorts class to the top of my form1.cs class.

How do I call the SelectionSort from class Sorts.

Following is some code snippets:

In form1.cs class:

using DSM.SortingAlgorithms; //at top of form1.cs

In private void Form1_Load(params here)
{
//define A[10] here

Sorts s = new Sorts();

s.SelectionSort(A) // does not work
.SelectionSort(A) // does not work
}

In SortingAlgorithm.cs module
namespace DSM.SortingAlgorithms
{
Sorts
{
public static void SelectionSort(int [] A)
{
//do stuff here
}

//other algorithms
};
}

.

Nov 15 '05 #3
Not sure what you mean, with the static method and using the
DSM.SortingAlgorithms namespace, your at one line of code:

Sorts.SelectionSort(A);

Tim
"David Miller" <da**********@cinfin.com> wrote in message
news:00****************************@phx.gbl...
that worked.

Is there any way to shorten that?

David
-----Original Message-----
Try DSM.SortingAlgorithms.Sorts.SelectionSort(A) or simply
Sorts.SelectionSort(A) if using the DSM.SortingAlgorithms

namespace. You
don't access static methods by instantiating the object.

"David Miller" <da**********@cinfin.com> wrote in message
news:06****************************@phx.gbl...
I have a form1.cs file where I am trying to call a sorting function from a SortingAlgorithms.cs file. They are part of the same solution, but even when I make the
SelectionSort algorithm public static, it does not appear in the intellisense, not does it let me call it. I tried even instantiating an object of type Sorts, the name of my class, but that did not help. Also, I added the namespace for the Sorts class to the top of my form1.cs class.

How do I call the SelectionSort from class Sorts.

Following is some code snippets:

In form1.cs class:

using DSM.SortingAlgorithms; //at top of form1.cs

In private void Form1_Load(params here)
{
//define A[10] here

Sorts s = new Sorts();

s.SelectionSort(A) // does not work
.SelectionSort(A) // does not work
}

In SortingAlgorithm.cs module
namespace DSM.SortingAlgorithms
{
Sorts
{
public static void SelectionSort(int [] A)
{
//do stuff here
}

//other algorithms
};
}

.

Nov 15 '05 #4
Sorry, I didn't see the second option you listed,
Sorts.SelectionSort(A). That is actually what I was
assuming it could do, I just didn't realize that after
specifying the namespace I would also have to specify the
class. Now that I have 2 classes in that namespace it is
immediately obvious why I must specify the class.

thanks for your help

David
-----Original Message-----
Not sure what you mean, with the static method and using theDSM.SortingAlgorithms namespace, your at one line of code:

Sorts.SelectionSort(A);

Tim
"David Miller" <da**********@cinfin.com> wrote in message
news:00****************************@phx.gbl...
that worked.

Is there any way to shorten that?

David
>-----Original Message-----
>Try DSM.SortingAlgorithms.Sorts.SelectionSort(A) or simply >Sorts.SelectionSort(A) if using the DSM.SortingAlgorithms
namespace. You
>don't access static methods by instantiating the
object. >
>"David Miller" <da**********@cinfin.com> wrote in message >news:06****************************@phx.gbl...
>> I have a form1.cs file where I am trying to call a

sorting
>> function from a SortingAlgorithms.cs file. They are

part
>> of the same solution, but even when I make the
>> SelectionSort algorithm public static, it does not

appear
>> in the intellisense, not does it let me call it. I

tried
>> even instantiating an object of type Sorts, the name

of my
>> class, but that did not help. Also, I added the

namespace
>> for the Sorts class to the top of my form1.cs class.
>>
>> How do I call the SelectionSort from class Sorts.
>>
>> Following is some code snippets:
>>
>> In form1.cs class:
>>
>> using DSM.SortingAlgorithms; //at top of form1.cs
>>
>> In private void Form1_Load(params here)
>> {
>> //define A[10] here
>>
>> Sorts s = new Sorts();
>>
>> s.SelectionSort(A) // does not work
>> .SelectionSort(A) // does not work
>> }
>>
>> In SortingAlgorithm.cs module
>>
>>
>> namespace DSM.SortingAlgorithms
>> {
>> Sorts
>> {
>> public static void SelectionSort(int [] A)
>> {
>> //do stuff here
>> }
>>
>> //other algorithms
>> };
>> }
>>
>>
>
>
>.
>

.

Nov 15 '05 #5

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

Similar topics

14
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild....
1
by: Ben | last post by:
I am having trouble calling functions in another file.. Lets look at the scenario below: File xyz.cc: (I have both xyz.h and xyz.cc, for simplicity I've avoided xyz.h) ------------ struct xyz...
13
by: RainBow | last post by:
Hi everyone, (Very Sorry, if this is the wrong group in which I am posting this query). Code snippet: //C library typedef int (*PFunc)(int* aArg); void call_c_foo(PFunc aPtrtoFunc) {
10
by: headware | last post by:
I know that you can call the method of one from from inside another form by doing something like this Forms("MyForm").MyFunction(12, 34) However, you have to know that MyForm has a function...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
17
by: Bill Grigg | last post by:
I have been successfully calling DLL's using VC++ 6.0 and also using VC++7.1 (.NET). I only mention this because I have never felt comfortable with the process, but nonetheless it did work....
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
6
by: yasodhai | last post by:
Hi, I have to call a function from one cs file to another. Kindly provide me the link where I can go and search for the material regarding this. Regards, Yasodhai
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.