Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Newbie question about C# class files

Reply
Thread Tools

Newbie question about C# class files

 
 
=?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=
Guest
Posts: n/a
 
      07-07-2005
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?
--
D @ premierdata
 
Reply With Quote
 
 
 
 
Mythran
Guest
Posts: n/a
 
      07-07-2005

"" <> wrote in message
news9ED9DD0-1525-4C7B-BA3C-...
> 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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=
Guest
Posts: n/a
 
      07-07-2005
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


"Mythran" wrote:

>
> "" <> wrote in message
> news9ED9DD0-1525-4C7B-BA3C-...
> > 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
>
>

 
Reply With Quote
 
Mythran
Guest
Posts: n/a
 
      07-07-2005

"" <> wrote in message
news:E9A4B725-F24C-4505-89D1-...
> 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

 
Reply With Quote
 
rypki rypki is offline
Junior Member
Join Date: Oct 2012
Posts: 1
 
      10-03-2012
Quote:
Originally Posted by Mythran View Post
"" <> wrote in message
news:E9A4B725-F24C-4505-89D1-...
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Newbie question about accessing a Variable out of a class of a class Christian Maier C++ 3 02-15-2007 08:24 AM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Newbie Question: Function of a class keeps "forgetting" data thats declared inside class Snoeys Andy C++ 2 09-12-2003 06:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57