ICode9

精准搜索请尝试: 精确搜索
  • C#6.0反射:提取只读自动属性的支持字段的名称2019-11-19 16:08:45

    我有一个序列化机制可以在专用字段上工作,以确定哪些应该序列化,哪些不应该序列化.该方法背后的主要思想是仅序列化数据的“本质”. 例: public class Person { private readonly string _firstName; private readonly string _lastName; public C1(string firstName,

  • C#-使用字符串格式格式化小数2019-11-19 07:05:00

    public static string PadZero(this double number, int decimalPlaces) { var requiredFormat = "0." + "".PadRight(decimalPlaces, '0'); var something = $"{number:requiredFormat}"; return numb

  • 没有表达式的C#字符串插值如何编译?2019-10-27 03:08:53

    编译器如何处理没有表达式的内插字符串? string output = $"Hello World"; 仍然会尝试格式化字符串吗?编译后的代码与带有表达式的代码有何不同?解决方法:对于此C#代码: string output = $"Hello World"; int integer = 5; string output2 = $"Hello World {integer}"; Console.W

  • C#-字符串插值2019-10-26 03:05:04

    这个问题已经在这里有了答案:            >            String Interpolation vs String.Format                                    2个 我是C#的初学者.到目前为止,我遇到了几种可用于将变量嵌入字符串值的方法.其

  • c# – 如何编写与基类一起使用的扩展方法2019-07-17 13:07:45

    想法是扩展我的功能的扩展方法. 所以不要有这样的东西: return Add(Add(storage.GetFirst(), 3), 7); 我想要这样的东西: return storage.GetFirst().Add(3).Add(7); 扩展方法的问题是它们必须在静态类中是静态的. 这是我想要做的简化示例. public class Storage {

  • c# – 为什么集合初始值设定项不与表达式body属性一起使用?2019-07-17 12:10:17

    我认为现在最好显示代码: class Foo { public ICollection<int> Ints1 { get; } = new List<int>(); public ICollection<int> Ints2 => new List<int>(); } class Program { private static void Main(string[] args) { var foo

  • c#主要构造函数(实验性特征)2019-07-06 18:09:06

    C#主要构造函数已从C#6中“删除”. class Point(int x, int y) { public int X { get; } = x; // this is supported, but now it's static only! public int Y { get; } = y; } 我无法从团队中找到任何迹象表明这个功能在未来有多大可能发生巨大变化. 我正在尝试找到更

  • c# – 内联隐式声明的out变量编译但不获得Visual Studio支持2019-07-03 08:02:58

    请考虑以下方案: 作品: SemanticModel semanticModel; document.TryGetSemanticModel(out semanticModel); 不起作用: var semanticModel; document.TryGetSemanticModel(out semanticModel); 作品: document.TryGetSemanticModel(out SemanticModel semanticModel); 工作,但: do

  • 编译器如何在c#中优化异常过滤器?2019-07-02 13:51:47

    在C#6中出现异常过滤器.所以我们可以写一些重试逻辑 public static void Retry() { int i = 3; do { try { throw new Exception(); } catch (Exception) when (--i < 0)

  • c# – 在调试器中跳过表达式身体属性2019-06-23 11:55:32

    是否有类似的[DebuggerStepThrough]属性可用于C#中的表达式身体属性? 例如,我想跳过代码 public Byte ByteArray => Builder.CreateArray(); [DebuggerStepThrough]无法应用于属性. C#团队是否在C#6.0中提供任何其他解决方案?解决方法:DebuggerStepThrough对于表达式身体属性无效,

  • c# – 为什么必须显式声明嵌套类型?2019-06-23 07:55:52

    我认为这是我第一次使用新的C#6字典初始化功能,我需要一个如下所示的嵌套结构: var map = new Dictionary<string, Dictionary<string, object>>() { ["WNodeScramblingResetZone_Unlock"] = { ["updater"] ="p

  • 来自C#6.0语法的错误2019-06-12 01:06:33

    参见英文答案 > How to enable C# 6.0 feature in Visual Studio 2013?                                    6个 Resharper建议我打开C#6.0.我喜欢这些变化,但在我看来,Visual Studio 2013和C#6.0并不是真的很喜欢彼此,因为当我将lambdas用于

  • 如何在C#6.0字符串插值中输入引号字符2019-06-12 01:06:14

    特定 IDictionary<string, string> x; 以前你可以做(​​作为带引号的参数代码示例): string.Format("{0}", x["y"]); 格式化C#6.0字符串插值的正确方法是什么? $"{x["y"]}" // compiler error due to the quotes on the indexer value // UPDAT

  • C#嵌套初始化陌生感2019-06-11 11:56:10

    在这些初始化语句编译的前提下 List<int> l = new List<int> { 1, 2, 3 }; Dictionary<int, int> d = new Dictionary<int, int> { [1] = 11, [2] = 22 }; Foo f = new Foo { Bar = new List<int>() }; 这不会 List<int> l = { 1, 2, 3 }; Dictionary&l

  • c# – 使用null传播事件的线程安全性2019-06-11 10:56:06

    参见英文答案 > Can I use null conditional operator instead of classic event raising pattern?                                    1个 这两个样本是否相同?可以用Invoke和null传播替换旧式的提升吗? 旧: public event EventHandler<M

  • c# – vNext选择输入的主要方法2019-06-09 18:52:41

    我没有看到任何相关的文档,但是看起来在vNext中,您可以愉快地使用非静态方法void Main()编译和运行应用程序.实际上,新的控制台应用程序模板为您提供了非静态主菜单.例如: public class Program { public Guid MyGuid { get; set; } = Guid.NewGuid(); void Main() {

  • C#6空条件运算符 – 作为代码转换器?2019-05-27 20:55:59

    在执行成员访问之前,我已经知道null条件运算符can be used to test for null. 例如 : int? length = customers?.Length; // null if customers is null Customer first = customers?[0]; 如果客户在客户中为空?.Length,那么客户?.Length将返回null并且null将在int中? length = …

  • c# – Expression-Bodied函数在get-property中使用的成员2019-05-27 07:52:30

    在编写类时,我可以通过两种方式在Get-property中使用Expression bodied函数: class Person { public string FirstName {get; set;} public string LastName {get; set;} public string FullName1 => $"{FirstName} {LastName}"; public string FullName2 { get =>

  • c# – 编译器中的错误还是误解?或短裤上的运算符2019-05-19 17:05:38

    参见英文答案 > Bitwise-or operator used on a sign-extended operand in Visual Studio 2015                                    2个 我有一行代码在VS2015中给我一个警告信息(CS0675),但在2013年没有. shortValue |= (short)anEnum; W

  • c# – Readonly getters VS属性函数2019-05-16 20:53:23

    C#6带来了一些新功能,包括getter-only auto-properties和property-like function members. 我想知道这两个属性之间有什么区别?我有什么理由喜欢彼此吗? public class Foo { public string Bar {get;} = "Bar"; public string Bar2 => "Bar2"; } 我知道{get;} =只能通过静

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有