Browsing 7239 questions and answers with Jon Skeet

Decimal separator comma but I want save data with point

I have to read and write an excel file. The problem is that when a PC is the decimal separator, (comma) also in the excel file numbers with the comma will be saved. I would like...
Jon Skeet
people
quotationmark

Convert.ChangeType(object, Type) uses the thread's current culture for conversion. It sounds like you want the invariant culture, so you should use Convert.ChangeType(object, Type, IFormatProvider): cell.Value =... more 11/21/2016 9:01:49 AM

people

Why can't I access instance properties in the Execute delegate of a DelegateCommand?

I'm used to using lambdas in ways apparently other than this. When I try and define a DelegateCommand, I have to access to non-static members of the enclosing type for the...
Jon Skeet
people
quotationmark

You're trying to access an instance member within an auto-implemented property initializer. That's like trying to do so in a field initializer. Basically, you can't reference this even implicitly in initializers, not even within lambda... more 11/21/2016 8:28:03 AM

people

Show wrong data using java 8 CompletableFuture

I wrote a simple example to understand CompletableFuture. But when I print it on console. Sometime It only show "asyn demo" This is my code public class DemoAsyn extends Thread...
Jon Skeet
people
quotationmark

You're starting the asynchronous operation, but you're not waiting for it to finish - when you've printed asyn demo there's nothing else keeping a non-daemon thread alive, so the process terminates. Just wait for the... more 11/21/2016 8:13:40 AM

people

Dictionary function for Character Contoller

using UnityEngine; using System.Collections; using System.Collections.Generic; public class Keyboard_Input : MonoBehaviour { public float speed = 5f; ...
Jon Skeet
people
quotationmark

You're declaring directions within the Start method, so it's a local variable. You should declare it as a field - and I'd make it a static field, as you don't need a different dictionary for each instance. You can use a collection... more 11/19/2016 9:23:04 AM

people

Create new derived type in constructor of abstract base

Apologies for the awful title, I couldn't think of a better way to phrase it. Essentially I have an abstract base class Category and whole host of derived classes inheriting from...
Jon Skeet
people
quotationmark

No, you can't do that - if you call new Foo(), that will always create an instance of Foo, never of a subclass. Instead, create a static factory method in Category: public static Category CreateCategory(string line) { if (line ==... more 11/18/2016 2:12:51 PM

people

Does calling .toArray() on an ICollection that is an Array return the reference or a copy?

I am working on a few extension methods where I need to transform the input collection into an Array. I want to save memory so I only want to create a copy of the input if it is...
Jon Skeet
people
quotationmark

ToArray always creates a copy. Your extension method does not behave the same way. Note that there are subtleties here around types as well. Consider this code: string[] x = { "a", "b" }; object[] y =... more 11/18/2016 9:27:55 AM

people

What requirements does Ant place on attribute names?

I can get my scriptdef to run but only if I use certain names for my attributes. Apparently names like "property" and "prop1", "prop2", etc. are ok, but most other names...
Jon Skeet
people
quotationmark

The attributes are lower-cased automatically. I found this out by putting self.log(attributes); into the script. So if you change your script to use propn instead of propN it works: project.setProperty(attributes.get("propn"),... more 11/17/2016 6:32:41 PM

people

Modify a dictionary in a for loop in C#

I am experienced in C/C++ but pretty much a newbie in C#. My question is pretty simple. Say we have a hash table with integer keys and values and we want to increment all the...
Jon Skeet
people
quotationmark

Dictionary<,> itself doesn't provide a good way of doing this - because updating the value associated with a key counts as a change that invalidates any iterator. ConcurrentDictionary<,> does allow this though, and even has an... more 11/17/2016 3:10:57 PM

people

C# shortcut for #if ... #else ... #endif like #define something as string

In C# dotNET for Mono, is there an easier way of doing this? #if __MonoCS__ public static SqliteConnection NewConnection #else public static SQLiteConnection...
Jon Skeet
people
quotationmark

Well, you can use a using alias directive: #if __MonoCS__ using SQLiteConnection = Foo.Bar.SqliteConnection; #endif Then you can use SQLiteConnection everywhere within the same file. You may want to use the adapter pattern to put this... more 11/16/2016 4:10:23 PM

people

Get max value of x field only from objects satisfying 'true' for y field

Say I've got a database of Person objects with the following fields: class Person { public DateTime BirthDate { get; set; } public string CountryOfBirth { get; set;...
Jon Skeet
people
quotationmark

Well, it sounds like you want to: Filter by country Group by birth date Order the groups in descending order Take the first group So (assuming the property names have been fixed to follow conventions): var query = db.People ... more 11/16/2016 9:30:31 AM

people