Browsing 7239 questions and answers with Jon Skeet

How return distinct records using LINQ

How can I get my code below to return distinct records. The relationship between courses and coursesstructures is one to many public IQueryable<object>...
Jon Skeet
people
quotationmark

It seems to me that the problem is your use of the second from clause - you're not using cs at all, so why bother with it? It's just introducing the duplication, because you're selecting one result per matching course structure. I would... more 4/13/2016 9:45:49 AM

people

golang timezone daylight savings time doesn't work

I know that on 26 Oct, 2014 02:00am the clock should go backwards 1 hour, but I can't reproduce this using a simple golang program const timeFormat = "2 Jan, 2006 3:04pm" loc,...
Jon Skeet
people
quotationmark

Given your output, it looks like this line: testz , _ := time.ParseInLocation(timeFormat, "26 Oct, 2014 01:59am", loc) ... is actually giving you the later of the two occurrences of 1:59am, given that it's showing an offset of +3. In... more 4/13/2016 6:07:05 AM

people

Why is this DateTime.ParseExact statement not working?

The following line gives me a "String was not recognized by a valid DateTime" error: DateTime.ParseExact("4/6/2016", "dd/MM/yyyy", Nothing) I got this "working" example on...
Jon Skeet
people
quotationmark

Your format says you'll have two digits for the day and the month. Your actual values only have one digit. You have two options: Follow the format you've specified, e.g. 04/06/2016 Change the format to match the value, e.g.... more 4/12/2016 5:17:13 PM

people

Are private members of the superclass also instantiated, when a subclass is instantiated?

In java, in a subclass, how can super() or non-private methods that were defined in the superclass access private members of the superclass, private members are not inherited...
Jon Skeet
people
quotationmark

The private fields aren't inherited, but they do exist. It really depends on what you mean by "inherited" here - and the JLS (e.g. in 8.2) is - I believe - referring to which members can be looked up by member resolution with respect to... more 4/12/2016 12:01:00 PM

people

Why C# cannot cast implicitly an Action<T> Where T : BaseType to Action<BaseType>

I try to cast an Action to is constraint type. Why C# cannot cast It ? If I force cast the return is null private Action<BaseObject> MyAction { get; set; } //Cannot...
Jon Skeet
people
quotationmark

Not every Action<TModel> is an Action<BaseObject>. Let's look at a concrete example: Action<string> and Action<object>. An Action<object> delegate can take any object reference as a parameter. It's perfectly... more 4/12/2016 9:21:53 AM

people

can a c# program start with a '{'; if not, why not?

My question, to which the answer is not known to me is stated in the title, i.e.: can a c# program start with a {; if not, why not? Everything that follows below details my...
Jon Skeet
people
quotationmark

However, the namespace-member-declarations are optional ~~ for that reason, perhaps the compiler should allow an intial {. No, that's not what it being optional means - it means "there doesn't have to be one", not "you can have... more 4/12/2016 5:50:46 AM

people

Is it possible to lose precision when only using multiplication and division of integers? How about using doubles?

In java, if we have an operation like below that only uses integers and multiplication and division, is it possible that result would not be equal to int3 due to lose of...
Jon Skeet
people
quotationmark

You're performing division using integer operands, so yes, that's very likely to lose information. It's quite the same as losing precision in the same way that normal floating point arithmetic loses precision, but it's still information... more 4/11/2016 4:54:22 PM

people

Using foreach to loop more than two list<string>

I'm trying to loop five list by merging them. I know that this works fine var zipped = letters.Zip(numbers, Tuple.Create); foreach (var tuple in zipped) { ...
Jon Skeet
people
quotationmark

The simplest approach would probably be to reimplement Zip yourself multiple times, e.g. public static IEnumerable<Tuple<T1, T2>> ZipTuple<T1, T2>( this IEnumerable<T1> source1, IEnumerable<T2>... more 4/11/2016 8:38:33 AM

people

NodaTime, should we use LocalDateTime for booking times?

We develop and maintain a booking system which has been used in Denmark for quite some years. However we are now expanding our reach to countries outside one timezone and some...
Jon Skeet
people
quotationmark

If you always know the time zone associated with the local date/time of the booking, that's mostly fine. Presumably the time zone is associated with the restaurant of the booking. The one problem you could run into is that a LocalDateTime... more 4/10/2016 12:23:55 PM

people

For Loop Multiplying Number

I need some help - At the end of a for loop, I need to set an original value to the next multiple of the value. This is what I have so far - int originalNumber = 1; for (int...
Jon Skeet
people
quotationmark

You don't need to change originalNumber at all - just multiply i by originalNumber: int originalNumber = 1; for (int i = 1; i <= 10000; i++) { int multiple = originalNumber * i; // Use multiple however you want to } To get... more 4/9/2016 11:54:46 AM

people