Browsing 7239 questions and answers with Jon Skeet

Delete Node out of an attribute XML C#

as i said in the Title i want to delete the node when i get a specific value out of an attribute. (in this case "install" out of the attribute "dependencyType") Xml...
Jon Skeet
people
quotationmark

This is the problem in the second code: XmlDocument doc = new XmlDocument(); doc.Load(filePath); var xml = XElement.Load(File.OpenRead(filePath)); For some reason, you're loading the XML document twice in this (and then ignoring doc) -... more 8/5/2014 6:47:18 AM

people

There is already an open DataReader ... even though it is not

Note: I've went through millions of questions when the issue is not disposing the reader/connection properly, or when the error is because of badly handled lazy loading. I believe...
Jon Skeet
people
quotationmark

I suspect this is the problem, at the end of the method: this.connectionPool.Putback(sqlConnection); You're only taking two elements from the iterator - so you never complete the while loop unless there's actually only one value... more 8/4/2014 10:22:00 PM

people

Date inequality is not functioning in android

I want to display a text when time is between 20:45 and 23:15 Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); if ((today.hour>=20 &&...
Jon Skeet
people
quotationmark

Yes, you just need to fix your logic. You only need to compare the minutes if the hour is a borderline hour. For example: if ((today.hour > 20 || (today.hour == 20 && today.minute >= 45)) && (today.hour < 23... more 8/4/2014 9:30:45 PM

people

printing backslashes in file paths

Suppose I have a file with a name starting with "n" (like "nFileName.doc"). Why is it that when I get its path as a string and print it to the console the "\n" sequence is not...
Jon Skeet
people
quotationmark

The concept of escaping is only relevant for source code (and other specific situations such as regular expressions). It's not relevant when printing a string to the screen - Console.WriteLine doesn't have any such concept as escape... more 8/4/2014 4:15:32 PM

people

System.Linq.Enumerable+d__3a`1[System.String] error in LINQ foreach loop

I have a list that I am trying to populate from another list in which I want to combine some data and eliminate some. In the original list the data looks like this: Id ...
Jon Skeet
people
quotationmark

You're calling ToString() on the result of Take and Select - and that's not going to do anything nice. It's not clear why you're calling ToString explicitly in Description, and for Text you really want FirstOrDefault or First instead, as... more 8/4/2014 2:48:07 PM

people

Convert String to Date exception

I know this question has been asked a lot but I can't find the solution to mine. I have an application where I'm converting a string to a date and I always catch the exception....
Jon Skeet
people
quotationmark

"MM" is "two digit month". You want "MMM" for "abbreviated name of month". Additionally, you should specify the locale so that it doesn't try to parse it in the user's locale - assuming it really will always be English: import... more 8/4/2014 2:39:37 PM

people

C# Dynamic "RuntimeBinderException"

I am initializing dynamic with ExpandoObject and adding some items to it. dynamic dy = new System.Dynamic.ExpandoObject(); dy.Property2 = new...
Jon Skeet
people
quotationmark

And it's absolutely right - List<T> doesn't have an ElementAt method. It only works in your original code because it's an extension method on IEnumerable<T>. Dynamic typing doesn't let you call extension methods using the... more 8/4/2014 2:26:19 PM

people

Java reads wrong values from binary structured file

I have a file which consist of Delphi records. The record looks like: TPoint = record X, Y: Double; end; As I know Delphi stores data as LittleEndian, and Java as BigEndian...
Jon Skeet
people
quotationmark

I suspect the problem may be because you're reading 8 bytes as a big-endian double when they're not a big-endian double. Given that bits have specific meanings in double, that could cause problems - Java may be normalizing NaN values, for... more 8/4/2014 2:03:45 PM

people

C#, compare two different type of lists

I have list of objects and I have list of strings. List<String> states = new List<String>(); states.add("wisconsin"); states.add("Florida"); states.add("new...
Jon Skeet
people
quotationmark

It sounds like you want something like: List<Person> people = ...; List<string> states = ...; var peopleWithKnownStates = people.Where(p => states.Contains(p.State)); Or just to find if any of the people have known... more 8/4/2014 1:58:28 PM

people

Moment js utc() time in london BST

I'm using momentjs lib to updated text on some ajax action. What I need to do is to set a current date & time in london. I'm using moment.utc() function but because of the...
Jon Skeet
people
quotationmark

If you want the local time instead of the UTC time, just use moment() instead of moment.utc(). You're specifically asking for UTC, so you shouldn't be surprised when you get UTC :) From the documentation: By default, moment parses and... more 8/4/2014 1:36:06 PM

people