Browsing 7239 questions and answers with Jon Skeet
A class can only contain declarations (and static/instance initializers). A field declaration can contain an initializer, as per firstName - and your declaration of lastName is valid, but the assignment after it is just a statement, and a... more 8/19/2016 9:13:48 AM
This is the relevant part of JLS 14.21: A try statement can complete normally iff both of the following are true: The try block can complete normally or any catch block can complete normally. If the try statement has a... more 8/18/2016 4:48:19 PM
LINQ is the way forward here, I'd say: public int[] Types => Enumerable.Range(0, NumberOfItems) .Select(i => GetTypeForItem(i)) .ToArray(); I've changed the names to... more 8/18/2016 2:24:25 PM
Just use IEnumerable instead of IEnumerable<object>; although an int[] doesn't implement IEnumerable<object>, it does implement IEnumerable: IEnumerable enumerable = myObject as IEnumerable; if (enumerable != null) { ... more 8/18/2016 11:19:19 AM
You need to customize the serializer itself. For example: serializer.Converters.Add(new ResultItemConverter()); I don't know whether you have to use a custom converter in this case, but that's how you can do so easily. more 8/18/2016 10:56:35 AM
You're calling FileInfo.Create(), which returns an open stream - but then you're not closing it, which prevents the next statement from opening the same file to read write to it. Further, I wouldn't expect you to have to create the file... more 8/18/2016 6:13:37 AM
It seems to me like your question can really be boiled down to: dynamic d = "x"; var v = Convert.ToString(d); ... the compile-time type of v is dynamic, as shown by hovering over it in Visual Studio, and you'd expect it to be string. No... more 8/17/2016 8:48:34 PM
However, I'm looking another elegant way of doing this rather than listing all the parameters of the super class in the sub class since it becomes lengthy when the number of attributes for the super class is huge. Well, the elegant... more 8/17/2016 8:09:51 PM
It sounds like you just want to parallelize your existing join. That's as simple as adding .AsParallel() to each source: var newList = from l1 in list1.AsParallel() join l2 in list2.AsParallel() on l1.Id equals l2.Id ... more 8/17/2016 5:42:11 PM
In addition to the two existing answers (git reset and git stash), I personally just ignore the extra commit (which almost has a commit message of wip...) until I'm ready to push the change somewhere remote, e.g. to github to create a pull... more 8/17/2016 5:38:28 PM