首页 > 解决方案 > The type or namespace name 'davetrainer' could not be found (are you missing a using directive or an assembly reference?)

问题描述

I'm new to C#, just programming for fun honestly, and I'm trying to create an object using a class in another file from my main one (my main file is called hello.cs, and the other file is called trainer.cs). They're both in the same folder, but when I try compiling hello.cs in the command line (using a path w/ .net), I get the error message in the title. I'm not using Visual Studio or a program like that, so a lot of answers I've found online don't really help.

This is my main file code:

using System;
using davetrainer;

namespace daveprogram {
    class Sure {
        public int addition(int a, int b) {
            return a + b;
        }


        static void Main() {
            Trainer dave = new Trainer("Dave", "water");
            Console.WriteLine("Hello!");
        }
    }
}

and this is trainer.cs:

using System;

namespace davetrainer {
    public class Trainer {
        string name;
        string spec;

        public Trainer(string a, string b) {
            name = a;
            spec = b;
        }

    }
}

Any help would be appreciated!

标签: c#classcompiler-errorsnamespaces

解决方案


推荐阅读