c#-6.0

Evaluation of method System.Linq.Enumerable.ToList() calls into native method Interop+Kernel32.FindStringOrdinal() in QuickWatch

こ雲淡風輕ζ 提交于 2021-02-19 03:42:51
问题 I have a list of posts that i get from DB like that: var iQueryablePost= from p in context.Posts select new Post { Id=p.id, Label=p.label }; var posts = new List<Post>(); posts = await iQueryablePost.ToListAsync(); I wanna filter my posts after getting all from DB, if i add where to my iQueryable it works just fine but i need to get all post from DB. That's what i did and the message I see in QuickWatch : posts = !string.IsNullOrWhiteSpace(query.PdcIdSITiers) ? posts.Where(c => c.Label

Difference between nameof and typeof

心不动则不痛 提交于 2021-02-17 15:17:05
问题 Correct me if I am wrong, but doing something like var typeOfName = typeof(Foo).Name; and var nameOfName = nameof(Foo); should give you exactly the same output. One of the understandable reasons according to this source: https://msdn.microsoft.com/en-us/library/dn986596.aspx is that "Using nameof helps keep your code valid when renaming definitions" If you want to get the class instance as string it is not possible to do something like that: var fooInstance = new Foo(); var nameOfName =

Difference between nameof and typeof

旧时模样 提交于 2021-02-17 15:14:40
问题 Correct me if I am wrong, but doing something like var typeOfName = typeof(Foo).Name; and var nameOfName = nameof(Foo); should give you exactly the same output. One of the understandable reasons according to this source: https://msdn.microsoft.com/en-us/library/dn986596.aspx is that "Using nameof helps keep your code valid when renaming definitions" If you want to get the class instance as string it is not possible to do something like that: var fooInstance = new Foo(); var nameOfName =

Difference between nameof and typeof

我与影子孤独终老i 提交于 2021-02-17 15:11:41
问题 Correct me if I am wrong, but doing something like var typeOfName = typeof(Foo).Name; and var nameOfName = nameof(Foo); should give you exactly the same output. One of the understandable reasons according to this source: https://msdn.microsoft.com/en-us/library/dn986596.aspx is that "Using nameof helps keep your code valid when renaming definitions" If you want to get the class instance as string it is not possible to do something like that: var fooInstance = new Foo(); var nameOfName =

Why is it not possible to use “Using static” feature with private enum? Is there any alternative?

一个人想着一个人 提交于 2021-02-16 20:32:27
问题 I have this class where I use a private enum. I would like to use C# 6 "Using static" feature, like the following: using static ConsoleForSimpleTests.Foo.MyEnum; namespace ConsoleForSimpleTests { public class Foo { private enum MyEnum { I, DonT, Want, This, To, Be, Public } private MyEnum value; public void SomeMethod() { switch (value) { case I: case DonT: case Want: case This: case To: case Be: case Public: break; } } } } NOTE: This does not compile and I understand why, it is due to the

Code Analysis Warning CA2213 - Call Dispose() on IDisposable backing field

馋奶兔 提交于 2021-02-07 11:18:23
问题 Wanted to post this, even though I figured it out as I was writing the question. Will post answer below. Getting the following warning with VS Code Analysis: Warning CA2213 'DBConn' contains field 'DBConn.k__BackingField' that is of IDisposable type: 'SqlConnection'. Change the Dispose method on 'DBConn' to call Dispose or Close on this field. But my code does call Dispose() on the DBConn property. Does it not on the backing field? I have other instances like this - where I am disposing of

How to handle nameof(this) to report class name

江枫思渺然 提交于 2021-02-06 09:55:44
问题 I'd like to use the following C#6 code var joe = new Self(); Console.WriteLine(joe); ... and get the following output: joe The following attempt class Self { public string Name { get; set; } = nameof(this); public override string ToString() { return Name; } } fails as nameof cannot be applied to this . Is it there a workaround for this problem? EDIT . The scenario I'm working with assures that no two references point to the same Self object. 回答1: No, nameof is designed to refer to the compile

Using null-conditional bool? in if statement [duplicate]

守給你的承諾、 提交于 2021-01-22 03:40:06
问题 This question already has answers here : Converting Nullable<bool> to bool (6 answers) Compiler Error for Nullable Bool (5 answers) cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) (9 answers) Closed 3 years ago . Why this code works: if (list?.Any() == true) but this code doesn't: if (list?.Any()) saying Error CS0266 Cannot implicitly convert type 'bool?' to 'bool' So why is it not a language feature making such an implicit conversion

Using null-conditional bool? in if statement [duplicate]

你说的曾经没有我的故事 提交于 2021-01-22 03:36:32
问题 This question already has answers here : Converting Nullable<bool> to bool (6 answers) Compiler Error for Nullable Bool (5 answers) cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) (9 answers) Closed 3 years ago . Why this code works: if (list?.Any() == true) but this code doesn't: if (list?.Any()) saying Error CS0266 Cannot implicitly convert type 'bool?' to 'bool' So why is it not a language feature making such an implicit conversion

Using null-conditional bool? in if statement [duplicate]

ぃ、小莉子 提交于 2021-01-22 03:36:29
问题 This question already has answers here : Converting Nullable<bool> to bool (6 answers) Compiler Error for Nullable Bool (5 answers) cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) (9 answers) Closed 3 years ago . Why this code works: if (list?.Any() == true) but this code doesn't: if (list?.Any()) saying Error CS0266 Cannot implicitly convert type 'bool?' to 'bool' So why is it not a language feature making such an implicit conversion