Browsing 7239 questions and answers with Jon Skeet
There are three rules at play here: The scope of a local variable is normally the entire block in which it's declared. The variables introduced via pattern matching in switch statements are slightly narrower than that, which is how... more 3/13/2018 2:11:57 PM
I create a semaphore with limit 1 and current value of 0. It should allow 1 thread to pass, right? No - the current value is 0, exactly as you wrote. Semaphore values count down when they're awaited - the count is effectively "the... more 3/10/2018 2:19:53 PM
It's important to understand that an integer is just a number. There's no difference between: int x = 0x10; int x = 16; Both end up with integers with the same value. The first is written in the source code as hex but it's still... more 3/8/2018 1:56:25 PM
I doubt that this has anything to do with async really. Currently you're copying one stream into a MemoryStream, but then leaving the "cursor" at the end of the MemoryStream... anything trying to read from it won't see the new data. The... more 3/7/2018 9:36:25 PM
This part is the problem: Where hasta_id='@hastaid' That's not using a parameter - that's searching for rows where the value of hasta_id is exactly the string @hastaid, because you've put it in a string literal. You need to get rid of... more 3/7/2018 5:51:57 PM
You shouldn't use Encoding.GetString to convert arbitrary binary data into a string. That method is only intended for text that has been encoded to binary data using a specific encoding. Instead, you want to use a text representation... more 3/5/2018 8:35:16 AM
Yes, that still loads the whole file's content into an in-memory representation. It's less useful than the XElement.Load(XmlReader) method which can be really useful to load just part of a document into memory at one time. I'd view the... more 3/2/2018 9:46:33 AM
Wrapping converts a non-nullable value type to its nullable equivalent. Unwrapping is the reverse. For example: int x = 5; int? y = x; // Wrapping int z = (int) y; // Unwrapping The C# spec doesn't actually call these "wrapping... more 2/27/2018 4:25:04 PM
Why does the compiler allow for omitting the return statement in the first case? Because the final } is unreachable. That's the condition that the compiler prevents (and that's in the specification): ever being able to reach the end... more 2/26/2018 4:17:25 PM
If you don't have the try/catch block, you'd only ever reach the statement that uses lengthCountdown if the assignment had succeeded anyway. If int.Parse or Console.ReadLine() throw a FormatException, you're currently catching that... more 2/25/2018 4:00:50 PM