Browsing 7239 questions and answers with Jon Skeet

get number of seconds since year 2000 using joda time

I am using JodaTime jar with Oracle Java 8. I am receiving packets from a firmware device and its beginning of time is beginning of day of January 1, 2000. I need to get the...
Jon Skeet
people
quotationmark

As others have said, this is due to integer overflow. You can just add brackets: return (int)((time.getMillis() - zeroPointTime.getMillis())/1000); But it would be cleaner to use Duration: Duration duration = new... more 7/9/2014 9:50:21 PM

people

Are private fields needed in a class where no methods exist?

I've been using ReSharper to do some work on cleaning up a C# codebase. I had been using both private fields in model classes along with public properties. However, I'm finding...
Jon Skeet
people
quotationmark

Methods are irrelevant here. If you have a property of: private int foo; public int Foo { get { return foo; } set { foo = value; } } Then it absolutely makes sense to turn that into: public int Foo { get; set; } If any other... more 7/9/2014 9:18:33 PM

people

How to make a button that shows the backspace (⌫) character on Android?

I'm trying to use the ⌫ character as my backspace symbol in my android app. When I just copy and paste this character as the text value of my Button it works and shows the symbol...
Jon Skeet
people
quotationmark

That character is not U+0008. U+0008 is a control character, without a graphical representation. ⌫ is U+232B (the "erase to the left" symbol), so if you use "\u232b" in your app it should be fine. more 7/9/2014 8:09:16 PM

people

Find properties that are equal in two generic lists

I can't find the oldItem with lambda (x = x.ID.Equals(newItem.ID)) - because it generics. I could provide another parameter like ID and use that to get the value of the property...
Jon Skeet
people
quotationmark

No, you'd normally provide the ID projection via another parameter: // Parameters renamed as they're not lists... private void LogDiff<T, TKey>(HashSet<T> newItems, HashSet<T> oldItems, ... more 7/9/2014 6:06:51 PM

people

Best way to offset an enumerable with itself

Given a source IEnumerable<T> and a positive integer offset and a merge function Func<T,T,TResult> I would like to produce a new IEnumerable<TResult> A possible...
Jon Skeet
people
quotationmark

Well, it sounds like you need to buffer the results, e.g. in an array: public static IEnumerable<TResult> Offset<T, TResult>( this IEnumerable<T> source, int offset, Func<T,T,TResult> selector) { // TODO:... more 7/9/2014 4:54:47 PM

people

Remove part of an XML attribute

I am parsing an XML document and saving it's content to a simple database via Microsoft Lightswitch application. The XML document contains some user accounts and has the following...
Jon Skeet
people
quotationmark

Look at your Account property: public String Account { get { return Account.Replace("i:0#.w|", String.Empty); } That's recursive... hence the stack overflow. Given your setter, I suspect you meant public String Account { get { return... more 7/9/2014 2:43:38 PM

people

C# reflection doesn't work with Point class?

I can't figure out what I am doing wrong. I've got this code: Point p = new Point(); //point is (0,0) p.X = 50; //point is (50,0) PropertyInfo temp =...
Jon Skeet
people
quotationmark

Ah, the joys of mutable structs. As Sergey said, Point is a struct. When you're calling PropertyInfo.SetValue, you're taking the value of p, boxing it (which copies the value), modifying the contents of the box... but then ignoring... more 7/9/2014 1:27:01 PM

people

Polymorphism java thinking

consider the following code: public class A{ private int num; public A(int n){ num = n; } public int getNum(){ return num; } public...
Jon Skeet
people
quotationmark

cause in run time y1 is of type B, and should go down to method f in class B? No: B.f() doesn't override A.f() because the parameter types are different. It overloads it. Overloads are picked at compile-time, not at execution... more 7/9/2014 10:36:20 AM

people

InputStream of Server and Client

My question is if the same InputStream is provided to both Client and Server. In my Server side I have: final socket...
Jon Skeet
people
quotationmark

No, the InputStream of the client receives the data from the OutputStream of the server, and vice versa. That's the whole point - each side receives the data sent from the other. more 7/9/2014 10:19:36 AM

people

Can I force the use of the 'using' statement for instances of my IDisposable class?

If my class (which in this case, takes care of database connections) implements IDisposable, is there a way I can force the use of of the using statement when instantiating my...
Jon Skeet
people
quotationmark

No, there's no language level support for this. However, you may find that tools such as FxCop or ReSharper can warn about it. (You'd need to work out how to integrate that into your workflow.) more 7/9/2014 10:15:18 AM

people