相关疑难解决方法(0)

C#代码中的美元符号是什么意思?

今天,我从我的客户端提取代码,我在这一行中收到错误.

throw new Exception($"One or more errors occurred during removal of the company:{Environment.NewLine}{Environment.NewLine}{exc.Message}");
Run Code Online (Sandbox Code Playgroud)

这条线也

moreCompanies = $"{moreCompanies},{databaseName}";
Run Code Online (Sandbox Code Playgroud)

$符号对我来说太奇怪了.这是C#代码.

c# c#-6.0

4
推荐指数
1
解决办法
589
查看次数

c#代码中=>运算符的含义

我有以下c#代码.我不知道=>这段代码中运算符的含义!!

public class ClassA: ClassB
{
    public string Type => "article";
}
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
75
查看次数

C#=>运算符有什么作用?(BESIDES是一名lambda运营商)

我知道C#operator =>是一个lambda运算符.但是今天我遇到了这样使用的运算符:

static readonly ResourceDictionary ResourceDictionary = new ResourceDictionary();
public static ResourceDictionary MyAppResources => ResourceDictionary;
Run Code Online (Sandbox Code Playgroud)

在这里,它似乎不是一个lambda运算符.任何人都可以告诉我这个操作员在使用时做了什么?

c# lambda operators

1
推荐指数
1
解决办法
68
查看次数

C#6.0 =>运营商

我正在使用visual studio 2013.我在github中找到了一个项目,该项目正在使用Visual Studio 2015.我正在尝试编译它但是我使用vs2013收到错误

令牌无效 ';' 在类,结构或接口成员声明中

这里是代码:

private readonly Log _log;
public Log Log => _log; // What => Operator is doing ? Pointer ?
Run Code Online (Sandbox Code Playgroud)

是的,=>运营商有哪些新功能C# [6.0]?并且有没有办法在vs2013中使用C#6.0?

c#

1
推荐指数
1
解决办法
243
查看次数

为什么"=>"赋值在这种情况下有效而不是"="?

我在我的工作中继承了一个C#MVC Web应用程序,并且在控制器类中直接有一个如下所示的赋值:

public class FooController : Controller
{
    private IAuthenticationManager AuthenticationManager => HttpContext.GetOwinContext().Authentication;
}
Run Code Online (Sandbox Code Playgroud)

Visual Studio突出显示错误,类似于"; expected".但它编译并运行得很好.如果我将"=>"更改为一个简单的赋值"=",它会突出显示HttpContext,并显示错误"非静态字段bla bla bla需要一个对象引用..."它将无法编译.

所以这是我的问题.为什么使用"=>"运算符编译并正常工作?我是C#的新手(来自Android/iOS开发),所以虽然很容易理解一些东西,但这样的东西让我感到困惑.

.net c# assignment-operator

1
推荐指数
1
解决办法
113
查看次数

字符串初始化时“=”和“=>”有什么区别

我只需要知道这两行之间有什么区别

private string somestring => "string";
private string somestring = "string";
Run Code Online (Sandbox Code Playgroud)

它们只是在控制台上打印相同的用途有什么区别

c# string operators

1
推荐指数
1
解决办法
63
查看次数

=> constant到{get;之间的差异 } =常数

在最佳实践和性能(如果有的话)的上下文中,什么更好地暴露在C#6+样式属性中作为属性设置或计算的值?

我正在比较表达身体的属性

public string Name => "bob";
Run Code Online (Sandbox Code Playgroud)

自动属性初始化

public string Name { get; } = "bob";
Run Code Online (Sandbox Code Playgroud)

对同样的事情有害吗?我在文档中的任何地方都找不到哪个用于我的案例.如果在SO中已经涵盖了这一点,我很抱歉,搜索让我无处可去.

c# c#-6.0

-1
推荐指数
1
解决办法
139
查看次数

它不是一种方法,它不是一个变量,它不是一个属性,它是什么?

我遇到了一些我今天不理解的事情.请考虑以下代码段:

public class EventStreamCollection<TKey, TValue>
{
    private readonly ConcurrentDictionary<TKey, TValue> _dictionary = new ConcurrentDictionary<TKey, TValue>();
    private readonly Func<TKey, TValue> _factory;
    public EventStreamCollection(Func<TKey, TValue> factory)
    {
        _factory = factory;
    }

    public TValue this[TKey key] => _dictionary.GetOrAdd(key, _factory);
}
Run Code Online (Sandbox Code Playgroud)

什么是这条线

public TValue this[TKey key] => _dictionary.GetOrAdd(key, _factory);
Run Code Online (Sandbox Code Playgroud)

它没有我能看到的名字.如果是的话,我想这将属于财产?它是什么以及它是如何工作的?

c#

-1
推荐指数
1
解决办法
79
查看次数

C#=>创建变量的语法

下面的代码用于在我正在查看的一些C#代码中初始化商店.但是我不理解这个上下文中的=>语法.

有任何想法吗?

protected new ServiceRepositoryStore<T> Store => (ServiceRepositoryStore<T>) base.Store;
Run Code Online (Sandbox Code Playgroud)

c#

-3
推荐指数
1
解决办法
74
查看次数

标签 统计

c# ×9

c#-6.0 ×2

operators ×2

.net ×1

assignment-operator ×1

lambda ×1

string ×1