Newbie question about C# class files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok, this is going to sound very trivial...

I have several methods that I want to put into a seperate class file and
call back to or reference from a couple different files.

I create the class file (class_utilites.cs) and am able to reference it's
main class object, but am unable to get to any of the included methods.

Here is the file to start!
<code>
using System;

namespace imageviewer_web
{
/// <summary>
/// Summary description for class_utilities.
/// </summary>
public class class_utilities
{
/// <summary>
/// This methods accepts from the master method the value and parses it to
determine if
/// it is a proper Township or Range value. If it is, it is then placed in
the proper
/// strings and passed back to the master method.
/// </summary>
/// <param name="val">The string containing either a Township or Range to be
processed.</param>
/// <returns></returns>
public string buildTR(string val)
{
string tempa = null;
if(val.IndexOf('.')>=0)
{
string [] parts = val.Split(new char[]{'.'});
return tempa = parts[0];
}
else
{
return tempa = val;
}
}
}

I have three or four more methods that I use all over the place that I want
to call back to but can't seem too.

What am I missing? Idea's?
 
Ok, this is going to sound very trivial...

I have several methods that I want to put into a seperate class file and
call back to or reference from a couple different files.

I create the class file (class_utilites.cs) and am able to reference it's
main class object, but am unable to get to any of the included methods.

Example:

namespace MyNamespace {
public class MyClass {
public string GetName()
{
return "My Name";
}
}
}

namespace MyNamespace {
public class MyClass2 {
public void DoSomething()
{
MyClass cls = new MyClass();
string name = cls.GetName();
// Do other stuff here.
}
}
}

HTH,
Mythran
 
Ok, so then using your example I should be able to from inside of one of my
other cs files type in MyClass2(variable) and have that method fire?
 
Ok, so then using your example I should be able to from inside of one of
my
other cs files type in MyClass2(variable) and have that method fire?

Either place both in one file, or separate them into two files:

<snip - Class1.cs>
namespace MyNamespace
{
public class Class1
{
public Class1()
{
}

public string GetName()
{
return "MyName";
}
}
}
</snip - Class1.cs>

<snip - Class2.cs>
namespace MyNamespace
{
public class Class2
{
public void DoSomething()
{
Class1 cls = new Class1();
string name = cls.GetName();
}
}
}
</snip - Class2.cs>

HTH,
Mythran
 
Back
Top