• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

C# classes

In a MS C# application, how would I do the following?  I'd like to call another function without using the class names.

Main.cs

using System;
using System.Collections.Generic;
using System.Text;


namespace IRule
{
    class Program
    {
        static void Main(string[] args)
        {
            runme();            
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace CKann
{
    public abstract class Foo
    {
           public static void runme()
           {
                   string blah;
           }
    }
}
0
thunderchicken
Asked:
thunderchicken
1 Solution
 
Gautham JanardhanCommented:
u will have to call it as
Foo.runme()
i dont think u can skip the class name
0
 
Babycorn-StarfishCommented:
hi,

if runme() was a static function within Program you could do that otherwise you need to fully qualify it with a class/instance name.
0
 
thunderchickenAuthor Commented:
Yeah, that's what I'm doing now, I don't want to do that.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
jasonclarkeCommented:
Can you post some code that demonstrates what you are doing (i.e. what calls you are making) and what you would like to do?
0
 
Babycorn-StarfishCommented:
i'm just curious at to why you wouldn't want to do that. Are you just after a shorthand for calling a method?
0
 
thunderchickenAuthor Commented:
I'm copying over a bunch of C code and I don't want to have to copy/paste the class name for each call.  There's a ton of global variables / enums / etc that it's using and it's a way to make it cleaner.
0
 
Babycorn-StarfishCommented:
if each method etc, was guaranteed to be uniquely named you could past it in then run through find replace for each method/enum and append the qualifying class/instance name, still pretty unwieldy process though.

Good luck!
0
 
thunderchickenAuthor Commented:
Yeah, that's what I'm doing now.  I know you can do this stuff in VB.NET, wasn't sure about C#.  Thanks
0
 
jaylorenzoCommented:
You have to inherit from Foo, as you have defined it as an abstract class.
That's the only way you can call the method.

Use it like:

public class Bar:Foo
{
  #region Foo Members
     public static void runme()
     {
          base.runme();
     }
  #endregion
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now