开发者

(Trivial?) C# namespace/class hierarchy problem

I am somewhat new to C# and I am puzzled by a compilation result belonging to a VERY small, simple and transparent program I have written and which is part of a university project. The code:

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

namespace Hemtenta_problem_1
{
    public class Basklass
    { 
        public virtual void SkrivTrams()
        {
            Console.WriteLine("Hej Hopp");
        }
    }
    public class Avledd_klass : Basklass
    {   
                    public override void SkrivTrams()
        {
            Console.WriteLine("Hej Hå");
        }
    }
    public class Avledd_klass_till : Avledd_klass
    {
        public new virtual void SkrivTrams()
        {
            Console.WriteLine("Tjo Hej");
        }
    }
    public class Ytterligare_avledd_klass : Avledd_klass
    {

    }_ //row which gives compiler message

    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

The compiler's message, relating to the row with the comment, is

A namespace cannot directly contain members such as fields or methods

Now, I perfectly well understand that any field or method can't be placed out there "in the open". It needs to be part of a class, and inside one. BUT IT IS NOT A FIELD OR A METHOD THAT I AM CODING, IT IS A CLASS IN ITSELF. None of the other classes, above in the code, gave this problem. It started when I wrote the very last and as ye开发者_如何学Pythont empty class.

Is Visual Studio's compiler working right? Or what is it in 40-odd lines that I am not seeing? Very grateful for comments that could help.


You have an _ after your closing } on the line where you have put your error code. You need to remove it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜