Browsing 7239 questions and answers with Jon Skeet

DateTime.TryParseExact with "ddd" format fails for all days except current

I encountered a strange issue. It's Wednesday now, and: DateTime date; DateTime.TryParseExact( "Wed", "ddd", null, System.Globalization.DateTimeStyles.None, out date); //...
Jon Skeet
people
quotationmark

I suspect the problem is that you've got a very incomplete date format there. Usually, DateTime.TryParseExact will use the current time and date for any fields that aren't specified. Here, you're specifying the day of the week, which isn't... more 7/1/2015 10:09:11 AM

people

Unable to cast object of type 'System.Int32' to type 'System.Reflection.RuntimePropertyInfo'

I have several entities that I'd like to transform. Here is an example: public class FromClass { public string Id { get; set; } public string Name { get; set; } ...
Jon Skeet
people
quotationmark

This line is the problem: var generic = methodInfo.MakeGenericMethod(toProp.GetType()); You're calling GetType() on toProp - that will return some type derived from PropertyInfo. You actually want the property type, so just change it... more 7/1/2015 9:06:26 AM

people

List to align, easiest way to realize

I have following list: 100 - 1.0 99 - 1.1 98 - 1.1 97 - 1.2 ... 23-28 - 5.6 ... 0-5 - 6.0 On the left side are the maximal reached points, on the right side the...
Jon Skeet
people
quotationmark

I'd start off with a data structure for the list you have. (This is assuming C# 6, by the way - for earlier versions of C# you wouldn't be able to use an auto-implemented readonly property, but that's about the only difference.) public... more 7/1/2015 7:47:06 AM

people

Why is Enumerable Min or Max inconsistent between collections of reference and value types?

When dealing with empty sequences, I was surprised to find out that the behavior for min or max is different depending on whether the source collection elements are of value type...
Jon Skeet
people
quotationmark

It's worth bearing in mind that nullable types (both nullable value types and reference types) behave differently to non-nullable value types in general when it comes to Min: a null value is treated as "missing" in general, so it's not... more 7/1/2015 7:19:15 AM

people

Extract type at runtime

I have a Type name being passed as an input . "MyApp.Modules.Common.contact". Using Activator.CreateInstance how do I construct this type in the method that I'm using. if I...
Jon Skeet
people
quotationmark

If you provide just the type name, Type.GetType will look in the currently-executing assembly, and mscorlib - but that's all. If you need to access a type in a different assembly, then either you need to get the assembly name in the type... more 7/1/2015 7:03:45 AM

people

Hebrew rendering in website

I am working on a product which has an internet "Admin Panel" - Somewhere the user can see information about the product. One of the minimal requirements is that the website has...
Jon Skeet
people
quotationmark

Basically, don't use FileReader. It always uses the platform-default encoding, which may well not be appropriate for this file. If you're using a modern version of Java, it's better to use: Path path =... more 6/30/2015 8:46:31 PM

people

How can I access elements in a LINQ query that is utilizing a groupBy?

I have two LINQ queries that I want to switch between depending upon the user's selection of a monthly report or yearly report. Before they were working but they were just giving...
Jon Skeet
people
quotationmark

Each element in the result of a GroupBy is a group - which itself then contains the elements, as well as a key. So you can do something like this: foreach (var group in sponsorRedemptions) { Console.WriteLine("Group: {0}",... more 6/30/2015 8:14:30 PM

people

How to compare two integer object?

Integer i = new Integer(0); Integer j = new Integer(0); while(i <= j && j <= i && i !=j ){ System.out.println(i); } Why does this while loop execute? I...
Jon Skeet
people
quotationmark

While == can be performed between two references (and is, when both sides are Integer), <= can't - so the compiler unboxes. So, your code is equivalent to: while (i.intValue() <= j.intValue() && j.intValue() <=... more 6/30/2015 5:48:25 PM

people

Loop for, strange outcome

I'm learning Java with the book "Java: A Beginner's Guide". The book shows this example of the for loop: // Loop until an S is typed class ForTest { public static void main...
Jon Skeet
people
quotationmark

You pressed s and then return. That "return" generated two more characters - \r and \n (I assume you're on Windows). Those are then returned by System.in.read(). Here's an example which makes that clearer: class ForTest { public... more 6/30/2015 5:45:17 PM

people

Why does my recursion program print a negative number?

My code for whatever reason is printing out a negative number when i run it with certain numbers(17). It is supposed to find the factorial of a number and print it out however...
Jon Skeet
people
quotationmark

You're encountering integer overflow. factorial(17) is 3.5568743e+14, which is well beyond the bounds of int. When an integer operation overflows, it can end up negative. For example: int x =... more 6/30/2015 5:37:58 PM

people