Calling function from another .cs file

  • Thread starter Thread starter David Miller
  • Start date Start date
D

David Miller

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
};
}
 
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.
 
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 said:
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
};
}


.
 
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 said:
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 said:
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
};
}


.
 
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 the
DSM.SortingAlgorithms namespace, your at one line of code:

Sorts.SelectionSort(A);

Tim


David Miller said:
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.

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
};
}




.


.
 
Back
Top