簡體   English   中英

VS2013 C#函數聲明=>符號

[英]VS2013 C# function declaration => sign

這段代碼在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);
        }
    }
}

在這種情況下, =>表示表達式身體成員 ,相當於:

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

但是,這種語法是在C#6中引入的,它需要Visual Studio 2015編譯器或更新版本。 切換到方法語法或升級您的Visual Studio版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM