.NET property generating “must declare a body because it is not marked abstract or extern” compilation error

后端 未结 9 1398
离开以前
离开以前 2021-02-13 20:03

I have a .NET 3.5 (target framework) web application. I have some code that looks like this:

public string LogPath { get; private set; }
public string ErrorMsg          


        
9条回答
  •  长发绾君心
    2021-02-13 20:34

    That error should not be coming from the code you posted. According to MSDN, you've done this right: http://msdn.microsoft.com/en-us/library/bb384054.aspx

    Hence I would recommend you re-check the error message, and where the compiler says the error is coming from. The text of the message you posted did not include a reference to properties, and there is a similar message for functions... Anything that is missing an implementation and not on an interface or marked abstract or extern can generate this error.

    The auto-property is a feature of the C# 3.0 language/compiler. If you are using VS 2008, it should work even if you are targeting .NET 2.0. I JUST tested it to make sure.

提交回复
热议问题