Browsing 7239 questions and answers with Jon Skeet

reverting from derivative to base class

I've initialized an object '_currDie' in the Die class, ran an if statement to change the object to a derivative class object, then run a method. The problem is that when it...
Jon Skeet
people
quotationmark

In each of your if statements, you're declaring a new local variable, e.g. if (chooseSides.SelectedItem.ToString() == "D4") { D4 _currDie = new D4(); } That initializes the new _currDie variable, but then you hit the end of the... more 7/22/2016 3:54:55 PM

people

What are the semantics of java's postfix increment operator on the left side of an assignment statement and why do they differ from the right side?

I was working on a leetcode question [1] and noticed something that caught my eye. When I write a line of code as: nums[i] = nums[(i++)+count]; I pass all the tests and my...
Jon Skeet
people
quotationmark

The answer lies in JLS 15.26.1. Basically, this is the order of things in the case of nums[i++] = nums[i+count]; nums is evaluated (as part of the left-hand side) i++ is evaluated to find the index; the result is the original value of... more 7/22/2016 5:10:51 AM

people

Linq Group By multiple fields and Flatten the list

I've got the following data title | useful ttitle1 | Yes ttitle1 | Yes ttitle1 | No ttitle2 | Yes I would like to group the above data and flatten it so I get...
Jon Skeet
people
quotationmark

It seems to me that the only problem is that you're grouping twice. I'd expect this to work: var query = from rating in ratings group rating by rating.ArticleTitle into g select new { ... more 7/22/2016 4:49:26 AM

people

XML Document to IEnumerable<XElement> and get values

Hey guys I'm trying to get some values from a deeper container in my xdocument but i always run in an Nullreference. This is my code so far: StreamReader...
Jon Skeet
people
quotationmark

You're calling Elements() on the XDocument, so that's just going to return the root element. You're then calling Element("ItemID") on that root element - asking for an element which doesn't exist. So that will return null, leading to your... more 7/21/2016 7:37:13 PM

people

Attribute Class, System.Attribute, Complex Type

It is possible do declare a AttributeClass with a filed and constructor of complex type? The answer is: No! see this post: https://stackoverflow.com/a/38509077/2935383 Scroll...
Jon Skeet
people
quotationmark

No, you can't do this. From section 17.1.3 of the C# Language Specification 5.0: The types of positional and named parameters for an attribute class are limited to the attribute parameter types which are: One of the following... more 7/21/2016 4:02:58 PM

people

Does C# 6.0 support .net core, or .net core responds to higher version of C#?

I've just installed .net core 1.0 and run the sample hello world. My question: Is there any relationship with .net core 1.0 and its default C# version? How can I know the C#...
Jon Skeet
people
quotationmark

The language itself isn't generally tied to a specific runtime/framework, although some language features do require framework features. (For example, interpolated strings are a bit more flexible on .NET 4.6 than on .NET 2.0 due to the... more 7/18/2016 7:19:04 AM

people

why does it freeze?

my objective is to make my button flexible depending on what is currently the value of my combo box, but the problem is when i run my program on that particular event it freezes,...
Jon Skeet
people
quotationmark

You're not changing the condition for your while loop - so if it's ever true, it will always be true: string selected = (string)cmbOperation.SelectedItem; while (selected == "ADD") { // Code that doesn't change the value of... more 7/17/2016 12:35:39 PM

people

Add elements contained in list and map them to a string

Input SomeName SomeFine OtherName OtherFine SomeOtherName SomeOtherFine OtherName SomeOtherFine SomeName OtherFine Explanation I want to make a...
Jon Skeet
people
quotationmark

The problem is that you're iterating over myMapList, but modifying it while you're iterating: myMapList.add(newMap); I still haven't quite got to grips with what you're trying to do, but fundamentally you shouldn't be adding to the... more 7/16/2016 9:58:02 AM

people

Convert Minutes to Milliseconds

The Timer class in Winforms has a property called, Interval and it Gets or sets the time, in milliseconds, before the Tick event is raised relative to the last occurrence of...
Jon Skeet
people
quotationmark

System.Windows.Forms.Timer.Interval is of type int - it's slightly confusing because System.Timers.Timer.Interval is of type double. So you're trying to assign the result of your method (a double) to a property of type int. That isn't... more 7/16/2016 8:20:44 AM

people

How does Google Cloud Datastore run locally?

While experimenting with Node.js and Google Cloud Datastore (for the backend of my application), I noticed that even without the Datastore Emulator, I was able to run and test my...
Jon Skeet
people
quotationmark

Where is this data being stored? In the cloud, just as if you were accessing it from the cloud. Just because your application isn't in the cloud doesn't mean that you can't access services in the cloud. Try running your application... more 7/15/2016 8:38:12 PM

people