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;
           }
    }
}
LVL 11
thunderchickenAsked:
Who is Participating?
 
jaylorenzoConnect With a Mentor Commented:
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
 
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
thunderchickenAuthor Commented:
Yeah, that's what I'm doing now, I don't want to do that.
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.