Browsing 7239 questions and answers with Jon Skeet

Mixing Reflection with Standard Calls

Let me preface this by saying that I am completely new to reflection. I have a Dictionary of string to Func<string, string>. I'd like to add a configuration section that...
Jon Skeet
people
quotationmark

I think all you're looking for is Delegate.CreateDelegate. You'll need to break the name you've got into a class name and a method name. You can then use Type.GetType() to get the type, then Type.GetMethod() to get the MethodInfo, then... more 9/27/2013 7:28:53 PM

people

Convert Hex to Byte with big string

I tried the different ways to convert hex to byte, there are four methods in the code, three of them I comment it out, only one there is no error when I run it, but I confused...
Jon Skeet
people
quotationmark

You're printing the result of calling toString on a byte[]. That's not going to give you what you want. For diagnostic purposes, use System.out.println(Arrays.toString(data)). And do that at the end of the loop rather than within it: for... more 9/27/2013 4:44:05 PM

people

How to multi sort elements in a List

How can I sort a list of 3 variables? The list has three values: clusCode, DocCode, and xValue. List<item> unSORT=new list<item>(); var okSORT=from element in...
Jon Skeet
people
quotationmark

Your question is very unclear, but I suspect you want something like: var okSORT = from element in unSORT orderby element.xValue descending, element.clusCode, element.DocCode select element; That's assuming you... more 9/27/2013 4:26:10 PM

people

Implements method of interface, method call and type cast

Consider the followoing code interface MyInterface{ void method(String s);// if we write static modifier we have compile error } class MyClass implements MyInterface{ ...
Jon Skeet
people
quotationmark

Why we cant define static method in interface? Interfaces are designed to work with polymorphism, basically. Polymorphism How would you know which implementation to call when calling a static method on an interface? // Should that... more 9/27/2013 4:08:50 PM

people

Illegal Start of Expression Java Boolean?

I'm trying to run a Bitwise number comparison and my code keeps coming up with an Illegal start of expression on line 30 of my code with the "if" statement. My code reads as...
Jon Skeet
people
quotationmark

An if statement is of the form: if (condition) statement You've currently got two bracketed conditions... which also end up assigning values, which probably isn't what you want. So first fix to get it to compile: if ((First_Relation =... more 9/27/2013 1:53:45 PM

people

Strange behaviour in implicit conversion if inline if used

I got a strange behaviour and I would like to understand it. But I haven't found good answers on the web :( Here's the situation, I've abstracted the name and logic to focus on...
Jon Skeet
people
quotationmark

Do you have any idea about this behaviour ? Absolutely. The type of a conditional operator expression must either be the type of the second operand or the type of the third operand. (And if those two types aren't the same, exactly one... more 9/27/2013 1:49:20 PM

people

Closing output stream 'misbehaving'?

In the following code: for(int i = 5; i <= 100; i+=5) { linearSurprise(i); // Function calling 'System.out.print()' System.setOut(outStream); //...
Jon Skeet
people
quotationmark

This assumption is invalid: 'outStrem' is closed so that when I recall my function, output will be sent to the console and not file. Why would it magically go back to the console? It will just be written to a closed stream... more 9/27/2013 1:35:29 PM

people

Character.isLetterOrDigit(char) returns different value in java 6 and 7

The following code snippet returns 46059 on Java 6 and 48757 on Java 7. Any ideas what might have changed? int i = 0; for(char c = Character.MIN_VALUE; c <...
Jon Skeet
people
quotationmark

I suspect this document holds the answer: New Scripts and Characters from Unicode 6.0.0 Early versions of the Java SE 7 release added support for Unicode 5.1.0. The final version of the Java SE 7 release supports Unicode 6.0.0.... more 9/27/2013 11:06:19 AM

people

variable declared within a loop maintains value through each iteration of the loop

I couldn't work out if this is a bug or a feature For i = 0 To 4 Dim strTest As String If i = 0 Then strTest = "test value" End If ...
Jon Skeet
people
quotationmark

It's well specified behaviour. From section 10.9 of the VB 11 specification: Each time a loop body is entered, a fresh copy is made of all local variables declared in that body, initialized to the previous values of the variables. Any... more 9/27/2013 10:50:42 AM

people

Notify when thread is complete, without locking calling thread

I am working on a legacy application that is built on top of NET 3.5. This is a constraint that I can't change. I need to execute a second thread to run a long running task...
Jon Skeet
people
quotationmark

The simplest approach is to add a callback, basically. You can even do this just using the way that multicast delegates work: ThreadStart starter = myLongRunningTask; starter += () => { // Do what you want in the callback }; Thread... more 9/27/2013 10:33:17 AM

people