.net

What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names?

倖福魔咒の 提交于 2021-02-06 15:19:18
问题 What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names? Long explanation of question follows below. I have determined that this not determined uniquely by any of: alphabetical order; declaration order; nor, name length. For example, consider that I want to have an enum where the numeric values correspond directly to a practical use, (e.g. rgb values for color). public enum RgbColor { Black = 0x000000, Red = 0xff0000, Green =

What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names?

半腔热情 提交于 2021-02-06 15:19:12
问题 What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names? Long explanation of question follows below. I have determined that this not determined uniquely by any of: alphabetical order; declaration order; nor, name length. For example, consider that I want to have an enum where the numeric values correspond directly to a practical use, (e.g. rgb values for color). public enum RgbColor { Black = 0x000000, Red = 0xff0000, Green =

How to store TimeZoneInfo objects in a database?

强颜欢笑 提交于 2021-02-06 15:18:32
问题 Somewhat misleading title, I know. Never actually wanted to store TimeZoneInfo object themselves: rather, I want to store some culture-neutral identifier, which can then be later used to reconstruct an instance of TimeZoneInfo . Currently, I'm storing the value of TimeZoneInfo.Id property and it seems to be OK both on English and Russian versions of Windows, but I just wanted to make sure I do the right thing. 回答1: Yes, Id is a non-localized identifier, so that's an appropriate thing to store

C++/CLI delegate as function pointer (System.AccessViolationException)

蹲街弑〆低调 提交于 2021-02-06 15:15:48
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

C++/CLI delegate as function pointer (System.AccessViolationException)

纵饮孤独 提交于 2021-02-06 15:14:34
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

Am confused about web.config in .NET Core

时光总嘲笑我的痴心妄想 提交于 2021-02-06 15:12:08
问题 There are a bunch of contradictory statements about web.config and .NET Core. Places saying it's gone. https://dotnetcore.show/episode-10-configuration-in-net-core/ Places saying it was gone but now it's back. https://stackoverflow.com/a/46771737/1662268 Places saying that it's no longer necessary, but you can create one manually: https://stackoverflow.com/a/43890405/1662268 https://stackoverflow.com/a/53731666/1662268 Additionally, I've just deployed a mostly-fresh-out-of-the-box .NET Core

C++/CLI delegate as function pointer (System.AccessViolationException)

旧巷老猫 提交于 2021-02-06 15:11:48
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

C++/CLI delegate as function pointer (System.AccessViolationException)

五迷三道 提交于 2021-02-06 15:11:27
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

Struct initialization and new operator

牧云@^-^@ 提交于 2021-02-06 15:01:39
问题 I have two similar structs in C#, each one holds an integer, but the latter has get/set accessors implemented. Why do I have to initialize the Y struct with new operator prior to assigning the a field? Is y still a value type when I init it with new ? public struct X { public int a; } public struct Y { public int a { get; set; } } class Program { static void Main(string[] args) { X x; x.a = 1; Y y; y.a = 2; // << compile error "unused local variable" here Y y2 = new Y(); y2.a = 3; } } 回答1:

Multiple Calls to HttpContent ReadAsAsync

纵饮孤独 提交于 2021-02-06 14:53:30
问题 Using Web API 2.2, suppose I want to read from HttpContent twice, each time as a different type. await httpContent.LoadIntoBufferAsync(); //necessary to buffer content for multiple reads var X = await httpContent.ReadAsAsync<T>(); //read as first type var Y = await httpContent.ReadAsAsync<Dictionary<string, object>>(); //read as second type When I run the above code, X is a non-null instance of T while Y is null. If I switch the order, Y will be a non-null dictionary while X will be null. In