Browsing 7239 questions and answers with Jon Skeet

String.Format Argument Null Exception

The below code will throw Argument Null Exception var test = string.Format("{0}", null); However, this will give back an empty string string something = null; var test =...
Jon Skeet
people
quotationmark

The difference is that the first piece of code is calling string.Format(string, object[])... whereas the second piece of code is calling string.Format(string, object). null is a valid argument for the second method (it's just expected to... more 7/1/2014 5:42:36 PM

people

Javascript, Date.parse with no timezone

I am having a problem with Javascript dates. I receive an JSON that contains a date, when I try to get the date object it returns the value in a different timezone and usually...
Jon Skeet
people
quotationmark

From the Mozilla documentation of Date.parse: ECMAScript 5 ISO-8601 format support Alternatively, the date/time string may be in ISO 8601 format. For example, "2011-10-10" (just date) or "2011-10-10T14:48:00" (date and time) can... more 7/1/2014 4:42:36 PM

people

NullPointerException when calling GetText()

First off, I'm an Android noob and I'm making a simple app that takes text from an EditText widget and shows it in a TextView when you tap on a button. But when the button is...
Jon Skeet
people
quotationmark

Here, in onCreate: Button b1 = (Button) findViewById(R.id.bttn1); EditText e1 = (EditText) findViewById(R.id.edit1); TextView t1 = (TextView) findViewById(R.id.txt1); ... you're declaring three local variables. Those are completely... more 7/1/2014 2:26:31 PM

people

C# Generics: Modify hidden inherited member in derived class

Say I have the following class structure: public class A { public string Name { get; set; } } public class B : A { public new string Name { get { return...
Jon Skeet
people
quotationmark

The generic method knows that value is of type B Not at compile-time it doesn't. When the compiler sees value.Name, it has to resolve that to one member... and the only member available to it is the one declared in A. Think of your... more 7/1/2014 12:28:58 PM

people

can't receive server full response

I'm using Java Socket Programming in order to receive server responses, I'm using a char array and read each response in it using read() method: InputStream stream = null; try{ ...
Jon Skeet
people
quotationmark

The problem is some times I can't receive the full response from the server and instead of that I receive like half of it and then the response after that I receive the other half. Yes. That's how stream protocols work. You shouldn't... more 7/1/2014 12:22:55 PM

people

WinRT Enhancing performance for adding Items of Collection to List

I have run over a small performance problem while I was trying to add some Items of an ObservableCollection to a ListView. Here's the ObservableCollection: private...
Jon Skeet
people
quotationmark

Given the documentation for ItemCollection, I suspect you want the ReplaceAll method: For implementations that track a "changed" event, the initial reset fires an event, but the items added don't fire discrete per-item events. So... more 7/1/2014 10:02:19 AM

people

Derived async delegate called twice

I am trying to reuse my custom control, overriding some event handlers in derived control. The code is like the follows: public partial class ControlBase : UserControl { public...
Jon Skeet
people
quotationmark

You're adding the Click event handler twice: once in the DerivedControl constructor, and once in the ControlBase constructor. If you only want a single handler (as I'd expect), just remove the subscription within the DerivedControl... more 7/1/2014 9:42:55 AM

people

Not able to convert a value from List<Long> at ith position to long

May be this is very simple but I am struggling a lot from hours. I have a list of Long which has got some 100 values in it. I have to loop through this list and have to get the...
Jon Skeet
people
quotationmark

Even though you're casting the result of q.getResultList() to a List<Long>, that cast doesn't really check that it's a List<Long>... because at execution time, it's really just a List. (This is due to type erasure in Java... more 7/1/2014 6:07:26 AM

people

Convert DateTime From String In C#

I use the following code for convert the date from String string JoiningDate="30/11/2013"; string[] dateconvert = JoiningDate.Split('/'); string...
Jon Skeet
people
quotationmark

Use DateTime.ParseExact, specify the format, and specify the invariant culture to make it absolutely non-system-dependent: DateTime dateTime = DateTime.ParseExact(text, "MM/dd/yyyy", ... more 7/1/2014 5:19:52 AM

people

Format double value?

I have following line of code: DecimalFormat df = new DecimalFormat("#.##"); System.out.println(df.format(23.00)); System.out.println(Double.parseDouble(df.format(23.00d))); System.out.println(df.parse("23.00").doubleValue()); First line print 23 but in 2nd and 3rd line when i convert it to double it prints 23.0 . showing 23.0 doesnt makes any sense. How can i get a double value 23. I checked these best-way-to-format-a-double-value-to-2-decimal-places how-to-nicely-format-floating-numbers-to-string-without-unnecessary-decimal-0
Jon Skeet
people
quotationmark

In the second and third output lines, you're just using Double.toString effectively. A double value doesn't remember whatever format it happens to have been parsed in to start with - it's just a numeric value. If you want to format a... more 6/30/2014 3:02:40 PM

people