.net

How to replace the HeaderCells of a DataGridView with custom headers?

◇◆丶佛笑我妖孽 提交于 2021-02-05 07:13:26
问题 When to replace a DataGridViewColumnHeaderCell with a custom HeaderCell (here: CustomDataGridViewColumnHeaderCell ), when the DataSource of a DataGridView is already set to a DataTable object and also preserve the text of the previous HeaderCell, which is set to the name of the corresponding Column of the DataTable? I have a custom header class for a DataGridView : public class CustomDataGridViewColumnHeaderCell : DataGridViewColumnHeaderCell { // adds a button to the header } A DataTable is

C# WebClient - DownloadString bad encoding

不问归期 提交于 2021-02-05 07:01:48
问题 I'm trying to download an html document from Amazon but for some reason I get a bad encoded string like "��K��g��g�e". Here's the code I tried: using (var webClient = new System.Net.WebClient()) { var url = "https://www.amazon.com/dp/B07H256MBK/"; webClient.Encoding = Encoding.UTF8; var result = webClient.DownloadString(url); } Same thing happens when using HttpClient: var url = "https://www.amazon.com/dp/B07H256MBK/"; var httpclient = new HttpClient(); var html = await httpclient

C# WebClient - DownloadString bad encoding

為{幸葍}努か 提交于 2021-02-05 07:01:04
问题 I'm trying to download an html document from Amazon but for some reason I get a bad encoded string like "��K��g��g�e". Here's the code I tried: using (var webClient = new System.Net.WebClient()) { var url = "https://www.amazon.com/dp/B07H256MBK/"; webClient.Encoding = Encoding.UTF8; var result = webClient.DownloadString(url); } Same thing happens when using HttpClient: var url = "https://www.amazon.com/dp/B07H256MBK/"; var httpclient = new HttpClient(); var html = await httpclient

Why is String.Empty an invalid default parameter?

╄→гoц情女王★ 提交于 2021-02-05 06:52:10
问题 If I type the following: public Response GetArticles(string Filter = String.Empty) { //Body } Visual Studio gives me this error: Default parameter value for 'Filter' must be a compile-time constant If I change the String.Empty to the classic "" it is fixed. But I'm still curious about what is wrong with the String.Empty and its behavior. 回答1: Why is String.Empty an invalid default parameter? Because "Default parameter value for 'Filter' must be a compile-time constant". And String.Empty is

Ternary Operator in C#

不打扰是莪最后的温柔 提交于 2021-02-05 06:50:53
问题 Can anyone please explain to me what happens behind the scenes when you use ternary operator? does this line of code: string str = 1 == 1 ? "abc" : "def"; is generated as a simple if / else statement? Consider the following: class A { } class B : A { } class C : A { } Now using ternary expression as follows: A a1 = 1 == 1 ? new B() : new C(); this doesn't even compile with this error: Type of conditional expression cannot be determined because there is no implicit conversion between

Ternary Operator in C#

夙愿已清 提交于 2021-02-05 06:50:26
问题 Can anyone please explain to me what happens behind the scenes when you use ternary operator? does this line of code: string str = 1 == 1 ? "abc" : "def"; is generated as a simple if / else statement? Consider the following: class A { } class B : A { } class C : A { } Now using ternary expression as follows: A a1 = 1 == 1 ? new B() : new C(); this doesn't even compile with this error: Type of conditional expression cannot be determined because there is no implicit conversion between

float arithmetic and x86 and x64 context

Deadly 提交于 2021-02-05 06:40:28
问题 We are running some code in both VisualStudio process context (x86 context) and out of VisualStudio context (x64 context). I notice the following code provides a different result in both context (100000000000 in x86 and 99999997952 in x64) float val = 1000f; val = val * val; return (ulong)(val * 100000.0f); We need to obtain a ulong value from a float value in a reliable way, no matter the context and no matter the ulong value, it is just for hashing purpose. I tested this code in both x64

create custom constant suffix in C#

与世无争的帅哥 提交于 2021-02-05 06:24:44
问题 i am trying to develop a class for unlimited size integer values, all i need is to make a new custom constant suffix used with the assign operator. For example: lets assume the class name is BigInt and the Suffix created is B the assign statement will be like this // B character will tell the compiler about the New Data Type BigInt x = 111111111111111111111111111111111111111111111111B; is there any way to achieve this? Special Regards 回答1: No, there isn't any way to do this in C# at this time

C# — TcpListener.Start() causing SocketException with message “Only one usage of each socket address”

让人想犯罪 __ 提交于 2021-02-05 06:21:11
问题 I have a service which as it's coming up invokes the Start() method on a TcpListener instance. This listener is using a port that is not common and not known to be used by any other services. Very very rarely for a span of minute or so it experiences an odd error. For a minute the service (which on failure restarts immediately) back to back crashes on the following exception: SocketException at System.Net.Sockets.Socket.DoBind(System.Net.EndPoint, System.Net.SocketAddress) at System.Net

Generate a Hashcode for a string that is platform independent

こ雲淡風輕ζ 提交于 2021-02-05 06:11:02
问题 We have an application that Generates a hash code on a string Saves that hash code into a DB along with associated data Later, it queries the DB using the string hash code for retrieving the data This is obviously a bug because the value returned from string.GetHashCode() varies from .NET versions and architectures (32/64 bit). To complicate matters, we're too close to a release to refactor our application to stop serializing hash codes and just query on the strings instead. What we'd like to