Browsing 7239 questions and answers with Jon Skeet
I would strongly advise you to separate out the "reading the data" from the "outputting HTML" sections of your code. It looks like you should create a data structure for an article, with properties for whatever the different bits in each... more 9/1/2014 9:12:00 PM
I'm assuming you want week 1 to begin on April 6th always, and be 7 days long, rather than having some rule like "Weeks always start on Mondays". Basically this is just a matter of: Working out which tax year you're in Finding the start... more 8/31/2014 7:39:00 PM
Yes, it's fine so long as nothing ever writes to the array. It will be initialized during type initialization, so all threads will "see" the values. For the sake of readability you might want to consider using an immutable collection... more 8/31/2014 4:42:54 PM
I strongly suspect that either child1 or child1.kind are of type dynamic, meaning that the expression is deemed to be a dynamically-bound expression, despite everything else. Here's a short but complete example to demonstrate what I... more 8/30/2014 8:46:44 PM
This is a problem with operator precedence. . has a higher precedence than a cast, so this: (loop) (e).a is being treated as: (loop) ((e).a) You want to cast and then use the result in the member access - so you need to bind the cast... more 8/30/2014 5:12:59 PM
Can an expression of the form obj.GetType().IsInterface ever be true in a codebase consisting exclusively of C# code? Yes - but probably not the way you were thinking of: using System; public class EvilClass { public new Type... more 8/30/2014 4:40:49 PM
No, it's not safe - if called from another method which is using generics. Here's a complete example which looks okay, but throws an exception: class Utility<K> { public K[] array(K... ks) { return ks; } ... more 8/30/2014 4:28:56 PM
It will build up the list in one pass, due to the way that LINQ streams the data. For example, take this: var query = list.Where(p => p.Number > n); That in itself doesn't look at any of the elements of the list. Instead, it... more 8/29/2014 5:32:24 PM
If you're just looking for a class whose direct base type is the relevant BaseClass<T>, you can use code like this: var targetBaseType = typeof(BaseClass<>).MakeGenericType(entityType); var type =... more 8/29/2014 4:55:44 PM
You're making changes to the array - but you're not putting the array itself on the stack... you're putting a reference to the array on the stack. You're basically pushing the same reference several times. If you want independent values,... more 8/29/2014 4:51:38 PM