【问题标题】:VS2013 C# function declaration => signVS2013 C# 函数声明 => 符号
【发布时间】:2017-05-16 23:16:35
【问题描述】:

这段代码在 vs2013 中给了我错误... 我现在不知道为什么......有人可以帮助我吗?! 我的问题是我不知道=> 是什么意思以及如何修复错误

using System;

namespace SmartStore.Core.Logging
{
    public static class LoggingExtensions
    {
        public static bool IsDebugEnabled(this ILogger l)                                               => l.IsEnabledFor(LogLevel.Debug);


    public static void Fatal(this ILogger l, string msg)                                            => FilteredLog(l, LogLevel.Fatal, null, msg, null);
    public static void Fatal(this ILogger l, Func<string> msgFactory)                               => FilteredLog(l, LogLevel.Fatal, null, msgFactory);

    public static void ErrorsAll(this ILogger logger, Exception exception)
    {
        while (exception != null)
        {
            FilteredLog(logger, LogLevel.Error, exception, exception.Message, null);
            exception = exception.InnerException;
        }
    }

    private static void FilteredLog(ILogger logger, LogLevel level, Exception exception, string message, object[] objects)
    {
        if (logger.IsEnabledFor(level))
        {
            logger.Log(level, exception, message, objects);
        }
    }

    private static void FilteredLog(ILogger logger, LogLevel level, Exception exception, Func<string> messageFactory)
    {
        if (logger.IsEnabledFor(level))
        {
            logger.Log(level, exception, messageFactory(), null);
        }
    }
}

【问题讨论】:

  • 错误是什么?
  • 没有错误...我只需要更改 C# 版本和 Visual Studio

标签: c# function visual-studio-2013 declaration


【解决方案1】:

在这种情况下,=&gt; 表示一个表达式体成员,相当于:

public static void Fatal(this ILogger l, Func<string> msgFactory) 
{ 
    return FilteredLog(l, LogLevel.Fatal, null, msgFactory); 
}

但是,此语法是在需要 Visual Studio 2015 编译器或更新版本的 C# 6 中引入的。切换到方法语法或升级您的 Visual Studio 版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 2012-07-15
    相关资源
    最近更新 更多