Newbie question about C# class files

Discussion in 'ASP .Net' started by =?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=, Jul 7, 2005.

  1. 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
    =?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=, Jul 7, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=

    Mythran Guest

    "" <> wrote in message
    news:D...
    > 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
    Mythran, Jul 7, 2005
    #2
    1. Advertising

  3. 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
    > news:D...
    > > 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
    >
    >
    =?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=, Jul 7, 2005
    #3
  4. =?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=

    Mythran Guest

    "" <> wrote in message
    news:...
    > 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
    Mythran, Jul 7, 2005
    #4
  5. =?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=

    rypki

    Joined:
    Oct 3, 2012
    Messages:
    1
    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.
    rypki, Oct 3, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,710
    Thomas Weidenfeller
    Oct 12, 2005
  2. Snoeys Andy
    Replies:
    2
    Views:
    405
    White Wolf
    Sep 12, 2003
  3. christopher diggins
    Replies:
    16
    Views:
    731
    Pete Becker
    May 4, 2005
  4. Joseph Turian
    Replies:
    5
    Views:
    576
  5. Christian Maier
    Replies:
    3
    Views:
    489
    John Harrison
    Feb 15, 2007
Loading...

Share This Page