Newbie question about C# class files

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?
 
M

Mythran

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
 
G

Guest

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?
 
M

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?

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
 
Joined
Oct 3, 2012
Messages
1
Reaction score
0
"(e-mail address removed)" <[email protected]> wrote in message
news:[email protected]...
> 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?
> --
> D @ premierdata
>


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

It doesn't work for me Mythran. I am doing this in VS, and I am not able to create object which definition is in separate file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top