Browsing 7239 questions and answers with Jon Skeet

hash value for a line object

Here is a reference implementation of Line object, my confusion is from line 40 to line 43, the question is, if two lines are different, but the OR results of slope/intercept...
Jon Skeet
people
quotationmark

Since I think same hash value means the same Line. No, it doesn't. This is a common misconception. If two objects have the same hash code, they may be equal - but they don't have to be. You should never treat equal hash codes as proof... more 10/10/2015 8:57:11 AM

people

bufferedReader readline=null

im trying to write a class where it would take a text file,reverse its contents and write it back. The way i want to do it is to write the lines in a String[] array,reverse the...
Jon Skeet
people
quotationmark

Your getNumberOfLines() method will read all the data from the BufferedReader - so unless you start reading the file again, there's nothing to read, and the very first call to readLine() will return null. However, instead of doing this,... more 10/10/2015 8:31:40 AM

people

Calender.getTime() not showing the date time of given timeZone

I am in timeZone +05:30 hrs and I want the time zone of Europe, so I am trying this:- TimeZone tmz=TimeZone.getTimeZone("Europe/Zurich"); Calendar calender=new...
Jon Skeet
people
quotationmark

You need to set the time zone in the SimpleDateFormat. A Date value doesn't have a time zone, so your initial code is fairly pointless - you could just call new Date(). Note that your format string is incorrect too - you're using minutes... more 10/10/2015 8:05:54 AM

people

Create Expression from PropertyInfo

I'm using an API that expects an Expression<Func<T, object>>, and uses this to create mappings between different objects: Map(x => x.Id).To("Id__c"); // The...
Jon Skeet
people
quotationmark

You just need Expression.Property and then wrap it in a lambda. One tricky bit is that you need to convert the result to object, too: var parameter = Expression.Parameter(x); var property = Expression.Property(parameter, propInfo); var... more 10/10/2015 6:56:03 AM

people

How to write just an # before some rows in a text file?

I have a text file who are like this : Rows ... product.people product.people_good product.people_bad product.boy #product.me ... Rows I want to put # before product. and the...
Jon Skeet
people
quotationmark

Currently you're reading the same text file twice - ones as individual lines and once as a whole thing. You're then rewriting a file as many times as you have lines. This is all broken. I suspect you simply want: // Note name changes to... more 10/9/2015 10:51:04 AM

people

Invalid Hexadecimal Characters in XML

I have an XML with invalid hexadecimal characters. I've read this, this and this and any other links given but failed to make it work. I'm using XmlReader - XmlDocument,...
Jon Skeet
people
quotationmark

It's unclear to me why CheckCharacters = false isn't fixing the problem for you, and as I've mentioned the far, far better fix is to get the data in a clean fashion to start with. However, you can work around this by replacing each... more 10/9/2015 10:23:53 AM

people

Inheriting generic abstract

I'm not sure if this is possible at all, looking for some clarification. I have a class structure like this: public class FooBase { //Some base class } public class...
Jon Skeet
people
quotationmark

Well, it can't be done directly - a FooBarHolderAbstract<Foo, Bar> isn't a FooBarHolderAbstract<FooBase, BarBase>. It's not clear whether or not you could logically have that, because we don't know what's in the abstract... more 10/9/2015 9:11:09 AM

people

Split function with dot on string in java

I am trying to split String with dot i am not able to get answer String dob = "05.08.2010"; String arr[] = dob.split("."); System.out.println(arr[0]+":"+arr[1]+":"+arr[2]);
Jon Skeet
people
quotationmark

String.split takes a regular expression pattern. . matches any character in a regex. So you're basically saying "split this string, taking any character as a separator". You want: String arr[] = dob.split("\\."); ... which is... more 10/9/2015 6:56:16 AM

people

HashMap.put() is overriding existing item for different key

I have a HashMap which I am using to store objects of type SplitCriteria using a String as the key Map<String, SplitCriteria> criteriaMap = new HashMap<String,...
Jon Skeet
people
quotationmark

but looking at the table contents there are only 6 objects present Nope, look at size - it's 7. You've just got two values in the same bucket. They don't collide by exact hash value, but they do collide by bucket. That's fine. You... more 10/8/2015 1:15:43 PM

people

Linq: Using ElementAt on a database

I am trying to get the 2nd element of a database using the Linq method, ElementAt. However I am getting the below error: LINQ to Entities does not recognize the method...
Jon Skeet
people
quotationmark

Firstly, be aware that ElementAt is 0-based - if you want the second element, you should be using ElementAt(1), not ElementAt(2). (Think of it like array indexing.) I'm not surprised that it's rejecting ElementAt on an unordered query,... more 10/8/2015 5:58:13 AM

people