Browsing 7239 questions and answers with Jon Skeet
When types are mutable, it's often useful to return a copy so that a client can't fundamentally modify your data, at least without telling you about it. Consider: public class Person { private Date dateOfBirth; public Date... more 9/6/2014 8:19:29 PM
You simply can't do this. In a 32-bit CLR, all objects must be less than 2GB in size. Even in a 64-bit CLR, you have to specify a special flag to enable larger arrays (<gcAllowVeryLargeObjects>) - and if your array is an array of... more 9/6/2014 7:50:28 PM
Well, I would separate the method out into two: A printChristmasTree method, which accepts the height as a parameter Your main method, which just deals with taking user input and calling printChristmasTree or exiting Most of your... more 9/6/2014 7:44:32 PM
This is the problem - or at least the initial problem: return new string(Encoding.UTF8.GetChars(bytes3)); The result of encryption is not a UTF-8-encoded byte array... it's arbitrary bytes. By assuming it's valid UTF-8-encoded text,... more 9/6/2014 7:39:02 PM
It's behaving exactly as documented - you're not getting "a random number", you're getting Long.MAX_VALUE: If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to... more 9/5/2014 9:34:22 PM
It's been in Java forever... the bit of the JLS you want is section 3.10.1: An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 interspersed with underscores, and can represent a... more 9/5/2014 9:28:22 PM
Your fields are private - which is a good thing, but it doesn't play well with Class.getFields (emphasis mine): Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented... more 9/5/2014 9:05:36 PM
If you don't need witch-specific calls, you can just ditch the _witch field and use the _character field - although I'd personally make it a private field with a protected property. If you need character-specific members, you should... more 9/5/2014 8:49:47 PM
You can't use the existing Action delegates with params, but you can declare your own delegate that way: public delegate void ParamsAction(params object[] arguments) Then: // Note that this doesn't have to have params, but it can... more 9/5/2014 4:44:46 PM
A Date object isn't in any time zone - it's just a wrapper around the number of milliseconds since the Unix epoch. The Unix epoch is typically described in terms of UTC (namely midnight at the start of January 1st 1970) but it's really... more 9/5/2014 4:15:21 PM