Browsing 7239 questions and answers with Jon Skeet

c# XMLReader skips nodes after using ReadElementContentAs

I am trying to parse an XML file and extract data from elements. The problem is that every time I use ReadElementContentAsX, the reader skips the next element. I don't know why is...
Jon Skeet
people
quotationmark

From the documentation of ReadElementContentAsString: This method reads the start tag, the contents of the element, and moves the reader past the end element tag. So you end up at the start of the next element. You then call Read()... more 7/28/2014 8:37:17 AM

people

why does the eclipse debugger use localhost for debugging ?

when we start the debugger in eclipse we see the following projectName.className at localhost:61744 in the debug window so could any explain the purpose or basically why does it...
Jon Skeet
people
quotationmark

The JVM is basically started using a network port for debugging. This allows the debugger to be on a different machine, which can be very useful at times. Now when you're debugging locally, the JVM has been started on your local machine -... more 7/28/2014 6:03:20 AM

people

runs false if statement when creating new threads

I'm writing a program that will email Cat Facts to anybody on a mailing list (not spamming, this is more of a learning experience than anything else). I have 2 arrays, 1 for facts...
Jon Skeet
people
quotationmark

Is this a problem with creating new threads? Sort of. It's a problem with capturing i in a lambda expression, and then changing it. It means that when the thread executes your lambda expression, it takes the current value of i, not... more 7/27/2014 8:32:17 PM

people

C# async await and threadpool

I understand that when using async and await on a method called on the UI thread that the UI thread can be freed to do other work while awaiting some IO to complete. If I use the...
Jon Skeet
people
quotationmark

In that case, the continuation executes on any available thread-pool thread. In theory it's up to the awaitable to schedule the continuation appropriately, but generally an awaitable captures the current SynchronizationContext when the... more 7/27/2014 8:16:25 PM

people

java.util.ConcurrentModificationException not thrown when expected

The following code throws a java.util.ConcurrentModificationException, as expected: public void test(){ ArrayList<String> myList = new ArrayList<String>(); ...
Jon Skeet
people
quotationmark

The iterator returned from ArrayList.iterator() in the implementation we're apparently both using only checks for structural modification in calls to next(), not in calls to hasNext(). The latter just looks like this (under Java... more 7/27/2014 12:00:01 PM

people

C# insert in table doesn't work but select works perfect

I work at a Windows Form C# application but i have some troubles. When I want to select from table everything works perfect ,but when i want to insert data in my table have not...
Jon Skeet
people
quotationmark

This is a problem, at least: insert.ExecuteReader(); That's meant for queries, because you're reading data. (As noted by Steve, it would still work - but it's not Call ExecuteNonQuery instead: insert.ExecuteNonQuery(); Additionally,... more 7/27/2014 8:35:55 AM

people

LINQ methods executing sequence

I am reading a book about C# in advanced level. And, now I am reading this part: Behind-the-scenes operation of the Linq query methods that implement delegate-based syntax. So...
Jon Skeet
people
quotationmark

It's not entirely clear what you mean, but if you're asking why you hit a breakpoint in the lambda expression in TakeWhile, but you don't hit one within Take, it's just that Take doesn't accept a delegate at all - it just accepts a number.... more 7/27/2014 8:16:53 AM

people

Main purpose of SwingUtilities invokeLater

I have this code snippet import javax.swing.SwingUtilities; public class Client1 { public static void main( String[] args ) { SwingUtilities.invokeLater( new...
Jon Skeet
people
quotationmark

Suppose the code within the run method modifies a UI element. If you try to execute that code from a non-UI thread, it will fail: all UI operations must be performed in the UI thread (aka the event dispatch... more 7/27/2014 7:25:35 AM

people

How to provide default value for a parameter of delegate type in C#?

In C# we can provide default value of the parameters as such: void Foo(int i =0) {} But, when the method signature is: void FooWithDelegateParam(Func<string,string>...
Jon Skeet
people
quotationmark

You can't, basically. Default values for parameters have to be compile-time constants. However, if you're happy to use null as a value meaning "use the default" you could have: void FooWithDelegateParam(Func<string, string>... more 7/27/2014 7:11:05 AM

people

List<XNode> retrieve certain Attribute

I have the following event: private void listBox_Items_SelectedIndexChanged(object sender, EventArgs e) { if (listBox_Items.SelectedIndex > -1) { ...
Jon Skeet
people
quotationmark

If you're just trying to select the value attribute, you should do that: var values = xDoc.Descendants("item") .Where(x => x.Attribute("id").Value == listBox_Items.Text) .Select(x =>... more 7/26/2014 6:23:40 PM

people