Browsing 7239 questions and answers with Jon Skeet

Unexpected character "

For some reason I am getting an error message Unexpected character " however it doesn't actually underline any of my code in read. I tried cleaning and rebuilding it but that...
Jon Skeet
people
quotationmark

You've got two "odd" characters within FindElement - U+200C (zero-width non-joiner) and U+200B (zero-width space) between the first "e" and the "m". The same characters occur in "Click" between the "l" and the "i". Just delete and retype... more 8/4/2017 8:52:59 AM

people

Unreachable objects on the stack cannot be garbage collected

Against my expectations, the following program import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.List; public class StackTest { public static void...
Jon Skeet
people
quotationmark

The problem is that you still have a list iterator on the stack, and that list iterator has a reference to the original list. That's keeping the list alive just as if you'd never set objects to null. An iterator has to keep a reference to... more 8/3/2017 7:05:59 AM

people

Why does char not autobox to Character in Java?

Working to improve ESAPI's encoding methods to handle non-BMP characters, I encountered unexpected behavior. It was interesting, to say the least... This unit test: public void...
Jon Skeet
people
quotationmark

Java can box char to Character perfectly easily. This will work fine: Character c = in; However, overload resolution occurs in multiple phases for the sake of backwards compatibility. In early versions of Java (before autoboxing) your... more 8/2/2017 6:25:16 AM

people

The error: System.Reflection.TargetParameterCountException was unhandled by user code

The code looks as following: public static class ResLocator { public static string Resolve(Type assemblyObjectType, string resourceName) { MethodInfo...
Jon Skeet
people
quotationmark

Here, you're specifying the types of the parameters for the method you're looking for: new[] { typeof(Assembly), typeof(string), typeof(bool), typeof(bool), typeof(ScriptManager) } Here, you're specifying the argument values to... more 8/1/2017 2:19:10 PM

people

TreeMap put is not working as expected

class Point{ int x, y, l; Point(int x, int y, int l){ this.x =x; this.y =y; this.l=l; } @Override public int hashCode() { ...
Jon Skeet
people
quotationmark

Your TreeMap is comparing Point values by the l part (whatever that's meant to be). That's what this part of your code does: new TreeMap<>((p1, p2)-> p1.l-p2.l); The two points you've created have the same l value (0) so... more 8/1/2017 12:42:20 PM

people

Check all list of values are in the enum c#

I have an integer list containing the ids List<int> ids = new List<int>; I am adding values in the list list.Add(100); list.Add(110); list.Add(120); I want to...
Jon Skeet
people
quotationmark

Enum.TryParse returns true for any numeric value. As per the documentation: If value is the string representation of an integer that does not represent an underlying value of the TEnum enumeration, the method returns an enumeration... more 8/1/2017 9:52:15 AM

people

IEnumerable<type> is false in code but true in Immediate Window?

Debugging some code I came across an "is IEnumerable" comparison, which confusingly evaluates to false in code but true in the Immediate Window. I wonder if anyone can shed...
Jon Skeet
people
quotationmark

It's a quirk of the intermediate window, basically. There are some pieces of code which evaluate differently there - it's one reason I generally prefer not to use the intermediate window. An IEnumerable<Fruit> isn't an... more 8/1/2017 8:50:10 AM

people

(Func, Action, Predicate) VS Converter and Comparison delegate c#

I understood Func, Action, Predicate with the help of some amazing posts available on this site and in short- Action is a delegate (pointer) to a method, that takes zero, one or...
Jon Skeet
people
quotationmark

Now I'm confused in Converter and Comparison delegate,why .Net Framework introduced these 2 delegate flavours for just converting and comparing, when and how to use these 2 over existing 3. Historically, the delegates were introduced... more 8/1/2017 7:35:46 AM

people

Waiting for Tasks to finish

I have 2 simple methods and I want process to not continue until they are finished completely. Because of this I used await Task.WaitAll(tasks); but compiler is giving me error in...
Jon Skeet
people
quotationmark

I suspect you meant WhenAll rather than WaitAll. WaitAll is a blocking call that returns all the results synchronously, when the original tasks have completed. You can't await that result, as it's not a task. WhenAll is an asynchronous... more 7/31/2017 1:35:02 PM

people

What is the reason that Encoding.UTF8.GetString and Encoding.UTF8.GetBytes are not inverse of each other?

Probably I am missing something, but I do not understand why Encoding.UTF8.GetString and Encoding.UTF8.GetBytes are not working as inverse transformation of each other? In the...
Jon Skeet
people
quotationmark

They're inverses if you start with a valid UTF-8 byte sequence, but they're not if you just start with an arbitrary byte sequence. Let's take a concrete and very simple example: a single byte, 0xff. That's not the valid UTF-8 encoding for... more 7/31/2017 7:55:37 AM

people