Browsing 7239 questions and answers with Jon Skeet

NumberFormatException on European Versions of Android?

I have an app which runs the following two lines of code upon starting: DecimalFormat decim = new DecimalFormat("#.00"); return...
Jon Skeet
people
quotationmark

Is it really possible that DecimalFormat is producing a comma version of the decimal on European phones? Yes, absolutely. That's what it's meant to do, after all: Creates a DecimalFormat using the given pattern and the symbols for... more 2/8/2014 1:46:55 PM

people

Partial FileStream Compression/Decompression

I am trying to make a file type which allows compression like a .png file, but every tutorial I find on (de)compression includes the entire stream. I need to be able to read the...
Jon Skeet
people
quotationmark

You just need to write an uncompressed header, and then create a compression stream after that. Here's an example: using System; using System.IO; using System.IO.Compression; using System.Text; class Program { private static void... more 2/8/2014 1:20:26 PM

people

Android User Location returning 0.0 for latitude and longitude

I have a class object which retrieves the users latitude and longitude. In my UI thread I create the object in the onCreate method that creates the Activity: userLocation = new...
Jon Skeet
people
quotationmark

Can anyone tell me the cause of this behavior? Well yes - presumably when it's showing 0, 0, onLocationChanged hasn't been called yet - because the location isn't known immediately. You've requested that the location manager calls you... more 2/7/2014 5:15:12 PM

people

Convert IDictionary<Guid,string> to the IEnumerable<SelectListItem>

How i can convert IDictionary<Guid,string> to the IEnumerable<SelectListItem>? I want to use string as SelectListItem.
Jon Skeet
people
quotationmark

Well you could just use dictionary.Values().Select(x => new SelectedListItem { Text = x }) Just be aware that it may not be in a useful order: Dictionary<,> is inherently unordered (or rather, the order may change and... more 2/7/2014 2:42:33 PM

people

Inherit a class to a constructor

public class abc { public abc():this(new pqr()) {} } The above code represents that the constructor abc() is inherited by some class. What does the above code...
Jon Skeet
people
quotationmark

The above code represents that the constructor abc() is inherited by some class. No it doesn't. It means that the parameterless abc constructor chains to the abc constructor taking a pqr. So you'd actually have: public class Foo { ... more 2/7/2014 11:00:15 AM

people

How to assign a value to sqlparameter NULL values without checking for null or 0?

The following check is needed to check for null values. is there a way i can do it directly? if(node.ID==0) { cmd.Parameters["@ID"].Value = DBNull.Value; } else { ...
Jon Skeet
people
quotationmark

For nullable types, I'd just use an extension method: public static object CoalesceNullToDBNull(this object input) { return input == null ? DBNull.Value : input; } Then use it as: cmd.Parameters["Foo"].Value =... more 2/7/2014 8:36:07 AM

people

Why default does not work with double parentheses?

Why this compiles: return default(T); but this does not: return default((T)); The full method is public static T PenultimateOrDefault<T>(this IEnumerable<T>...
Jon Skeet
people
quotationmark

Well, that's just not how the language is specified. It's important to understand that default is like typeof - they're operators1, not method calls. It's not like the name of the type is an argument - it's an operand, and the operand is... more 2/7/2014 8:24:59 AM

people

what happens with new String("") in String Constant pool

if i create a string object as String s=new String("Stackoverflow"); will String object created only in heap, or it also makes a copy in String constant pool. Thanks in...
Jon Skeet
people
quotationmark

You only get a string into the constant pool if you call intern or use a string literal, as far as I'm aware. Any time you call new String(...) you just get a regular new String object, regardless of which constructor overload you... more 2/7/2014 7:40:56 AM

people

LINQ OrderBy().ThenBy() not working

I am converting a project of mine from using an SQL Server based Entity Framework model, to using a local SQLite database. So far everything is going well, but for some reason I...
Jon Skeet
people
quotationmark

Looking at the source, it seems the author doesn't understand LINQ properly: They haven't provided a ThenBy method, but instead they're collecting multiple orderings with multiple OrderBy calls They haven't exposed the table as an... more 2/7/2014 7:08:38 AM

people

class defination in c# with different method

I want to define a class in C#. I found these two methods: Method 1 : public class customer { private string _name ; private string _family; public string Name { ...
Jon Skeet
people
quotationmark

I wouldn't do either of these. You're introducing a method called AddCustomer on a customer class. I wouldn't expect a Customer to know about a database - I'd expect some sort of data access layer or customer repository to know about it... more 2/6/2014 6:46:34 PM

people