Browsing 7239 questions and answers with Jon Skeet

Get this error when I try to debug. "An exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll but was not handled in user code"

I am trying to make a application that makes all the first letters to capital letters and the others to small. string navn = txtNavn.Text; string delnavn1, delnavn2; delnavn1 =...
Jon Skeet
people
quotationmark

I suspect this is the immediate problem: navn += delnavn1 + delnavn2 + " "; You're concatenating with the previous value of navn. So if you start off with "Hello there", when you get to the first space you'll have: delnavn1 = "... more 3/4/2015 9:24:31 PM

people

How to make datetime.now return date in UK format with c#

I want datetime.now to return the datetime object in UK format. It does so on my local computer but when I upload the code to the server it does it in US format
Jon Skeet
people
quotationmark

I want datetime.now to return the datetime object in UK format. There's no such concept, any more than an int is a value "in hex" or "in decimal". A DateTime is just a DateTime - you can specify the format when you convert it to a... more 3/4/2015 8:24:00 PM

people

Adding return in finally hides the exception

I have the following code public static void nocatch() { try { throw new Exception(); } finally { } } Which gives the error Exception in...
Jon Skeet
people
quotationmark

The error disappears because your code is now valid. (Not nice, but valid.) If a finally block just has a straight return; statement, then the overall try/catch/finally or try/finally statement can't throw any exceptions - so you don't... more 3/4/2015 6:06:35 PM

people

Chain Increment Operators

Why can you not chain operators? int test = 5; test++++; OR int test = 5; ++test++; This code gives a compile time error. The operand of an increment or decrement...
Jon Skeet
people
quotationmark

Basically, it's due to section 7.6.9 of the specification: The operand of a postfix increment or decrement operation must be an expression classified as a variable, a property access, or an indexer access. The result of the operation... more 3/4/2015 5:00:14 PM

people

Java SimpleDateFormat decrementing date by one day

I am trying to reformat a date string using sdf. SDF is decrementing the date by a day. Pointers would be helpful. java version "1.8.0_31" Input: ...
Jon Skeet
people
quotationmark

This is the problem: new Date(Input) You should not use that. Instead, construct a SimpleDateFormat to parse your input: import java.text.*; import java.util.*; public class Test { public static void main(String[] args) throws... more 3/4/2015 2:40:52 PM

people

Why anonymous method can be pass to a delegator's constructor?

Action<int, string> s = new Action<int, string>(delegate(int a,string b){}); Action<int, string> ss = delegate(int a, string b) { }; Why these both work? Why...
Jon Skeet
people
quotationmark

You're not really making a constructor call in the normal way, even though that's what it looks like. Instead, this is a delegate-creation-expression as described in the C# 5 specification, section 7.6.10.5: A... more 3/4/2015 11:03:34 AM

people

java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList

Can you explain me why does this happen and how can I fix it please? So I'm using Oracle-ADF and I'm using shuttle components. I get the selected values using the...
Jon Skeet
people
quotationmark

Arrays.asList returns a List implementation, but it's not a java.util.ArrayList. It happens to have a classname of ArrayList, but that's a nested class within Arrays - a completely different type from java.util.ArrayList. If you need a... more 3/4/2015 10:11:35 AM

people

Convert UTC timezone into AWST timezone in ZF2

I am trying to convert the timezone with below piece of code which is working fine except AWST timezone. $date = time(); $timeZone = "AWST"; $dt = new...
Jon Skeet
people
quotationmark

I suspect the problem is that you need to specify an IANA time zone ID rather than just an abbreviation. Time zone abbreviations are really problematic for various reasons: They usually indicate "half" a time zone; "Europe/London"... more 3/4/2015 9:31:35 AM

people

Error, String not recognized as valid DateTime when trying to ParseExact time string

The following fails after executing the highlighted line. String was not recognized as a valid DateTime. It's happening all the sudden, worked when it was 12PM or so... ?...
Jon Skeet
people
quotationmark

You should be using hh:mm:ss tt as the format string - HH is for the 24-hour clock, at which point you're saying it's 4AM... but with PM as the AM/PM signifier. Basically, use hh with tt, or HH on its own. Using Noda Time, you'd... more 3/3/2015 10:03:11 PM

people

Why does Class#getDeclaredMethods0 fail when trying to invoke main?

Why does this code snippet fail with IllegalArgumentException: wrong number of arguments? Demonstrated code works with ordinary member and static methods, as well as with native...
Jon Skeet
people
quotationmark

It's not clear why you're calling getDeclaredMethods via reflection, but the invocation of main is broken because you're trying to call it as if it had several String parameters - one per value in args. Instead, you want to pass a single... more 3/3/2015 3:20:11 PM

people