Invalid token '=' in class, struct, or interface member declaration c#

前端 未结 3 941
时光说笑
时光说笑 2020-12-11 18:49

this may be a simple question for people, but I can\'t see why this is occurring. here is my code 1st:

using System;
using System.Collections.Generic;
using         


        
3条回答
  •  感情败类
    2020-12-11 19:32

    It looks like this error happens due to version your MSBuild, old version of MSBuild can only compile C# version 4, while your code written in C# version 6 format (set default value for properties).

    Example of code writing in C# version 6:

     public static string HostName { get; set; } = ConfigurationManager.AppSettings["RabbitMQHostName"] ?? "";
    

    For MSBuild to compile your code, you need to write in C# 4 style

    public static string HostName { get; set; }
    public SomeConstructor()
            {
                HostName = ConfigurationManager.AppSettings["RabbitMQHostName"] ?? "";... }
    

    Or

     public static string HostName
            {
                get
                {
                    return ConfigurationManager.AppSettings["RabbitMQHostName"] ?? "";
                }
            }
    

    Hope it helps

提交回复
热议问题