Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:15:09+00:00 2026-06-18T10:15:09+00:00

I’m quite new to C#, and have made a class that I would like

  • 0

I’m quite new to C#, and have made a class that I would like to use in my main class. These two classes are in different files, but when I try to import one into the other with using, cmd says says

The type or namespace name “MyClass” could not be found (are you missing a using directive or an assembly reference?

I know that in Java I have to mess around with CLASSPATH to get things like this to work, but I have no idea about C#.

Additional details:

As you’ve probably figured out, I’m compiling and executing via command prompt. I’m compiling my non-main class using /target:library (I heard that only main classes should be .exe-files).

My code looks like this:

public class MyClass {
    void stuff() {

    }
}

and my main class:

using System;
using MyClass;

public class MyMainClass {
    static void Main() {
        MyClass test = new MyClass();
        /* Doesn't work */
    }
}

I have tried to encompass my non-main class with namespace MyNamespace { } and importing that, but it doesn’t work either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:15:11+00:00Added an answer on June 18, 2026 at 10:15 am

    UPDATE: As of C# 6, if you want to use the static members of a class without specifying the class name, you can use the using static directive to import the static members into the current scope, like this:

    using static MyNamespace.MyClass;
    

    Although this is not what the original question is about, you get a similar error to the one OP gets, so I’m providing it for completeness.

    Answer to OP’s question:

    using is for namespaces only – if both classes are in the same namespace just drop the using.

    You have to reference the assembly created in the first step when you compile the .exe:

    csc /t:library /out:MyClass.dll MyClass.cs
    csc /reference:MyClass.dll /t:exe /out:MyProgram.exe MyMainClass.cs
    

    You can make things simpler if you just compile the files together:

    csc /t:exe /out:MyProgram.exe MyMainClass.cs MyClass.cs
    

    or

    csc /t:exe /out:MyProgram.exe *.cs
    

    EDIT:
    Here’s how the files should look like:

    MyClass.cs:

    namespace MyNamespace {
        public class MyClass {
            void stuff() {
     
            }
        }
    }
    

    MyMainClass.cs:

    using System;
    
    namespace MyNamespace {
        public class MyMainClass {
            static void Main() {
                MyClass test = new MyClass();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.