Browsing 7239 questions and answers with Jon Skeet

Why is the hash code of args in main method confined in some sets of values only?

I have a program which only needs one random number, the random number can be insecure, so I am trying to use the hash code of args as random number because it does not require...
Jon Skeet
people
quotationmark

You're calling hashCode() on an array. Arrays don't override hashCode(), equals() or toString() - so you're getting a result which doesn't depend on the content of the array at all, and probably depends on where it happens to be in memory.... more 3/10/2016 6:53:47 AM

people

Unicode escape behavior in Java programs

A few days ago, i was asked about this program's output: public static void main(String[] args) { // \u0022 is the Unicode escape for double quote (") ...
Jon Skeet
people
quotationmark

Why Unicode escapes doesn't behave as normal escape sequences? Basically, they're processed at a different point in reading the input - in lexing rather than parsing, if I've got my terminology right. They're not escape sequences in... more 3/9/2016 7:52:15 PM

people

Remove CDATA from the input

I get a string which has CDATA and I want to remove that. Input : "<Text><![CDATA[Hello]]></Text><Text><![CDATA[World]]></Text>" Output I want...
Jon Skeet
people
quotationmark

It seems to me that you shouldn't be using a regular expression at all. Instead, construct a valid XML document be wrapping it all in a root element, then parse it and extract the elements you want. You also want to replace all CDATA... more 3/9/2016 4:41:31 PM

people

How to create Calendar with specific TimeZone?

I'm creating a Calendar object: Calendar calendar = new GregorianCalendar(2014, 0, 1); and calendar.getTime() returns Wed Jan 01 00:00:00 BRT 2014 that...
Jon Skeet
people
quotationmark

Just reverse the order of "specify date, specify time zone" to "specify time zone, specify date": Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.set(2014, 0, 1, 0, 0,... more 3/9/2016 12:39:43 PM

people

Declaring Variables as static: Unexpected behaviour

I am developing a Java Spring project that uses Spring data. It uses repositories to remove Dog Objects from a Kennel Object when the dog is collected by its owner. Note that...
Jon Skeet
people
quotationmark

Note that there can be multiple dogs associated with the one Kennel. There are also many kennels. Currently there is nothing associated with an individual Kennel. The fact that all your variables are static means that they are... more 3/9/2016 10:40:21 AM

people

how to traverse parent node till root element in xml in c#

I am trying to access parent node hierarchy till root element from child element in C# and want to store it in string. In the below xml, I would like to access parent nodes of...
Jon Skeet
people
quotationmark

Well, to get from one XElement to its parent, you can just use the Parent property - but in this case you want all the ancestors, so you can use the AncestorsAndSelf() method. That returns the ancestors in reverse document order, but you... more 3/9/2016 6:51:13 AM

people

Trouble assigning value to integers inside a function to be referred to later scope issue I think

I'm learning C#. (6 hours in) I'm more comfortable with Ruby and Javascript and am finding C# fun, yet way tighter in what it will allow you to do, so I am rediscovering simple...
Jon Skeet
people
quotationmark

Well you need to decide whether these numbers are meant to be part of the state of your object or not. If they are, make them fields. If they're not, don't. In this case, I'd probably keep them as local variables and change your NumSelect... more 3/8/2016 7:08:35 AM

people

Casting a generic class. (cast) vs Class.cast()

I have searched for my use case and found some interesting answers but they are not as suitable as i need. What would the appropriate way to do...
Jon Skeet
people
quotationmark

I think that both methods do the same. No, they don't. Because at execution time, the first code doesn't know the type of T due to type erasure. That means the cast basically does nothing within the method. The calling code might... more 3/8/2016 6:53:41 AM

people

How to use LINQ.Where for specific indexes

As the title says i need a LINQ expression which is going to check only few indexes of array. I currently have it like this : int[] a = b.Where(c => c % 4 ==...
Jon Skeet
people
quotationmark

If you want to use the index within your predicate instead of the value, use the overload of Where which accepts a predicate which checks a value/index pair: int[] a = b.Where((value, index) => index % 4 == (int) Cards.CardSuits.Club) ... more 3/7/2016 10:12:21 PM

people

MS SQL commas VS point in decimal type

We busy running c# asp website with MS SQL DB. Some of the columns have been assigned type decimal(18,2). SqlCommand cmd = new SqlCommand("select * from TABLE",...
Jon Skeet
people
quotationmark

But since my copy of source code is the same as my colleages as well as that of dev server, all controlled by SVN, how could it differ? Because the default system culture isn't defined in the source code. I very much doubt that you... more 3/7/2016 3:32:45 PM

people