Browsing 7239 questions and answers with Jon Skeet

Add second indexer to Math.NET Numerics

Not sure how to meet the demands of stackoverflow on this one... I'd like to modify the MathNET Numerics package so that I can use the indexer to access or assign to a sub-matrix...
Jon Skeet
people
quotationmark

No, there's no such thing as an "extension indexer" right now. Extension methods are as close as you can get. However, it's entirely possible (but not guaranteed) that they'll come in C# 8. So your options are: Wait for C# 8 Use your own... more 7/20/2017 8:28:52 PM

people

Why doesn't name exist in the current context of shorthand member initialisation?

I am using an object initializer for a st object: public class Container { public Container () { ContainedItem = new Item; } public Item ContainedItem { get; set;...
Jon Skeet
people
quotationmark

You can assign values to "sub-properties" as it were, just not with that syntax. Here's a complete example: using System; public class Container { public Item Item { get; set; } = new Item(); } public class Item { public string... more 7/20/2017 10:24:33 AM

people

Linq functions give strange compile error when ambiguous use of IEnumerable possible workarounds?

Given code similar to the following (with implementations in the real use case): class Animal { public bool IsHungry { get; } public void Feed() { } } class Dog : Animal { ...
Jon Skeet
people
quotationmark

As you say, the error message is unfortunate, in that the problem is ambiguity rather than Where not being found at all (assuming you have a using directive for System.Linq). The problem is that the compiler can't infer the type argument... more 7/20/2017 10:08:49 AM

people

I have converted dll to exe and build then it shows error exe does not contains static main method suitable for an entry point

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc { public class Class1 { public...
Jon Skeet
people
quotationmark

The entry point needs to be called Main, not main. That's also in-keeping with .NET naming conventions, which I'd strongly urge you to follow: Your namespace should be capitalized, e.g. Abc rather than abc Your display method should be... more 7/20/2017 6:18:42 AM

people

How to Sort a list of strings and find the 1000 most common values in java

In java (either using external libraries or not) I need to take a list of approximately 500,000 values and find the most frequently occurring (mode) 1000. Doing my best to keep...
Jon Skeet
people
quotationmark

I'd separate this into three phases: Count word occurrences (e.g. by using a HashMap<String, Integer>) Sort the results (e.g. by converting the map into a list of entries and ordering by value descending) Output the top 1000... more 7/19/2017 3:34:55 PM

people

JObject contains a C# keyword how to access it?

I am using the JQuery QueryBuilder plugin on my site, which compiles it's data into JSON. On the server side code, I take the JSON that is returned from the plugin and parse it...
Jon Skeet
people
quotationmark

You can use @ to use a keyword as an identifier, so this should work: string _operator = item.@operator; Alternatively, you may well find that indexer access would be fine: string _operator = item["operator"]; more 7/19/2017 3:06:19 PM

people

Add the XAttribute to XElement if attribute exists in the element

Need to add XAttribute newatt = new XAttribute("TAG", value); to XElement elem, but the elem could already contain the attribute with the name "TAG", so the elem.Add(newatt);...
Jon Skeet
people
quotationmark

You don't need to check whether the attribute already exists before using SetAttributeValue. Just: // Unconditional elem.SetAttributeValue("TAG", value); (There's no point even creating the XAttribute yourself.) From the... more 7/19/2017 10:39:54 AM

people

Need help understand VB conditional logic and find equivalent in java

I have a legacy project in Visual basic that needs to be converted to java. I cant understand the following line... If lastSendToggle And 128 Then ... where lastSendToggle is...
Jon Skeet
people
quotationmark

The operation x & 128 will never result in 1 for any value of x, because it's a bitwise operation. It will always either be 128 or 0, depending on whether that bit is set in x or not. (Note that 128 decimal = 10000000 binary, so... more 7/19/2017 10:27:13 AM

people

Is LocalDateTimeDeserializer from jsr310 deserializing zulu dates correctly?

I have an angular/spring boot application, on client side I'm using a primeng calendar input component, which takes the local date and converts it to UTC zoned date-time. I then...
Jon Skeet
people
quotationmark

No, it's doing the right thing IMO. A LocalDateTime isn't "local to the server", it's "not in any specific time zone". If you've got a text value which indicates a date/time and any sort of time zone indicator (e.g. an offset from UTC or... more 7/18/2017 11:05:12 AM

people

Get index of value in hashset C#

Is it possible to retrieve index of value in HashSet ? I have a hashset: HashSet<int> allE = mesh.GetAllNGonEdges(nGonTV); And I would like to retrieve index of value...
Jon Skeet
people
quotationmark

The "index" is meaningless in a HashSet - it's not guaranteed to be the same as the insertion order, and it can change over time as you add and remove entries (in non-guaranteed ways, e.g. if you add a new entry it could end up in the... more 7/18/2017 9:03:51 AM

people