Browsing 7239 questions and answers with Jon Skeet

Incorrect parsing of date strings in SimpleDateFormat

I'm trying to convert a string formatted date in UTC to a date object which is resulting a conversion that is off by a couple of minutes. SimpleDateFormat fullDateFormater = new...
Jon Skeet
people
quotationmark

SSSSSS is parsing a number of milliseconds - not microseconds, as you're expecting. 788810 milliseconds is 13 minutes, 8 seconds and 810 milliseconds. So your result is actually 2014-07-07T18:27:31.810. Yes, this is a really stupid bit... more 7/7/2014 6:46:27 PM

people

Lambda Expressions, Compare item1, if they are equal compare item2

I tried to search but I cannot seem to find my answer. I think an answer may exist as it not a uncommon question. I trying to say Sort by Item1. If they are equal, sort by...
Jon Skeet
people
quotationmark

While you can build a comparer to do this with List<T>.Sort, it's much easier to use LINQ, which is built for this sort of thing: sorted = unsorted.OrderBy(x => x.Item1).ThenBy(x => x.Item2).ToList(); If you really want to... more 7/7/2014 6:43:14 PM

people

how do i refactor these linq properties?

i have 4 class properties that have similar signatures but going to different linq properties. how do i create a delegate or something to clean this up? for example: ...
Jon Skeet
people
quotationmark

It sounds like you want somethng like: private IEnumerable<SelectListItem> GetDistinctOrderedLogs<T> (Func<TraceLogs, T> extraction) { return TraceLogs.OrderBy(extraction) .Select(extraction) ... more 7/7/2014 5:45:47 PM

people

Windows 8 store app XmlWriter does not write anything to file

I am not very well versed with .NET's XML libraries and trying to wrap my head around IXmlSerializable interface. I am developing a windows store app (W8) and wish to use the...
Jon Skeet
people
quotationmark

Given the comment thread - this was about not closing all the resources. You're disposing fs (manually, if no exceptions are thrown) but not x. You should really use using statements for everything like this: using (var stream = await... more 7/7/2014 5:00:21 PM

people

Convert to datetime from Oracle

i know there are a lot of similar questions, but I couldn't find what I was looking for. Here is my oracle date: string testdate= "2014-01-07 15:00:00.0000000"; And here is...
Jon Skeet
people
quotationmark

I'd start by trying to avoid getting it as a string in the first place. Make sure you're using the appropriate data type in Oracle, and you should be able to call GetDateTime on the appropriate DataReader (or whatever you're using). If... more 7/7/2014 4:54:40 PM

people

The functionality of the || operator

I have created an equals method. I believe I can do it in two ways but java doesn't seem to agree. Here is the first example which I know works. public class HelloWorld { ...
Jon Skeet
people
quotationmark

The right-hand side of the || operator isn't executed if the left-hand side evaluates to true, as per JLS section 15.24: The conditional-or operator || operator is like | (ยง15.22.2), but evaluates its right-hand operand only if the... more 7/7/2014 4:36:02 PM

people

SimpleDateFormat format removes leading zero from milliseconds

I'm having difficulties formating milliseconds with SimpleDateFormat. I'm trying to get accurate millisecond output with pattern "SS", but when millisecond starts with zero...
Jon Skeet
people
quotationmark

SS is just "the number of milliseconds, 0-padded if necessary to give a 2-digit result". So it looks like it's behaving as expected by the documentation. Personally I think it would be more sensible if it were specified (and implemented)... more 7/7/2014 1:19:21 PM

people

Linq Remove one anonymous list from another

I've seen many answers to this - but can't seem to get them to work: var numinqtoday = bc.SSRecs.Where(x => x.DateTime == id).Select(n => new { refer =...
Jon Skeet
people
quotationmark

You've got a list of groups there - and I suspect you'll find that one group is never equal to another. I suspect you want to perform the Except operation before the grouping. For example: var numinqtoday = bc.SSRecs.Where(x =>... more 7/7/2014 1:15:31 PM

people

Generic IComparable implementation issue in Mono

This code executes successfully in .NET 4.0 public void CompareTest() { var m1 = new Foo { Order = 1 }; var m2 = new Foo { Order = 2 }; var c1 =...
Jon Skeet
people
quotationmark

Firstly, this looks like it's probably a Mono bug in Comparer<T>.Default, which should notice if T implements IComparable<Foo> for some Foo that is either an interface T implements, or a base type of T. For workarounds, four... more 7/7/2014 1:12:52 PM

people

C# string toCharArray out of range exception

I came across this issue while I was fixing someone else's code. apparently they were trying to control digits after the decimal point like this: public static bool...
Jon Skeet
people
quotationmark

what argument is out of what range? Well, I'd expect the exception to tell you that - but I'd also expect it to be the second argument. (EDIT: Looking at the exception you actually get, even from .NET, it's actually blaming the first... more 7/7/2014 9:35:13 AM

people