Browsing 7239 questions and answers with Jon Skeet

SortedSet custom order when storing a class object

I'm looking at replacing a HashSet with a SortedSet because it is better suited to the data I'm storing. However, all the examples I've seen so far relate to storing simple...
Jon Skeet
people
quotationmark

Assuming by "indexer" you mean "ordering", you just make your type implement IComparable<Foo>, and provide a CompareTo method which compares the date within this to the date within the other Foo. Or you could implement... more 1/21/2015 12:28:01 PM

people

BigDecimal Rounding discrepancy using string and (int, long, double) constructors

What is the difference between using different constructors in bigdecimal when using round off. When running the below code: public class RoundTest { /** * @param args ...
Jon Skeet
people
quotationmark

Why does round off using string constructor give a different result than the others? Because it's the only time you're actually passing in a value of exactly 4.645. The rest of the time, you're passing in the double value closes to... more 1/21/2015 10:20:57 AM

people

Why the number of calls generated by LINQ FirstOrDefault or First

I've noticed some performance issues with our application and have tracked it down to sheer number of calls to ID properties on our classes. I've set up a sample to explain. We...
Jon Skeet
people
quotationmark

You're basically saying "for each address within Addresses, evaluate this predicate, until the predicate returns true, at which point return that address." The predicate is the lambda expression, which uses the Person_Id property, so it... more 1/20/2015 7:37:42 PM

people

lambda in vb.net: Select certain objects of a list, based on an attribute of a list of object within the first object

The question's title isn't super clear, but I had a hard time formulating it any better. I'll show an example of what I am trying to do. Function foo(id As Integer) As List(Of...
Jon Skeet
people
quotationmark

Basically you don't need to call Select at all - you're only performing a filtering operation, which is what Where gives you. You're not trying to transform the list. So just use: Return MasterListOfVersions.Where_ (Function(version)... more 1/20/2015 7:34:20 PM

people

Why do async unit tests fail when the async/await keywords aren't used?

According to this discussion, there should be no difference between the following two methods: public async Task Foo() { await DoSomethingAsync(); } public Task Foo() { ...
Jon Skeet
people
quotationmark

It sounds like those test runners may be using reflection to check whether the method returning Task really is an async method. That doesn't mean the method would behave differently if they were run - but they're just not being run. It's... more 1/20/2015 7:16:00 PM

people

TcpClient disposed prematurely

I have a problem I cannot seem to figure out, please help. I have created a class to handle an interface to some HW using TcpClient. I want this class to send one last command to...
Jon Skeet
people
quotationmark

Please tell me why an object which is clearly not yet out of scope is being disposed. Objects don't have a concept of "scope" as such. At the end of your program, both the TcpClient and the instance of your class are eligible for... more 1/20/2015 4:46:51 PM

people

dynamic variable not accepting inherited properties without typecasting

I have this dynamic variable by which I serialize a json string. dynamic result = serializer.Deserialize<dynamic>(json); From this I am fetching result["success"] which...
Jon Skeet
people
quotationmark

But it does, with LINQ, right? No, it doesn't. There's an extension method on IEnumerable<T> of First(), but extension methods can't be called on dynamic values in the "normal" way. However, you can use it as a normal static... more 1/20/2015 4:15:48 PM

people

Hashmap + Insertion Order

I read about HashMap and it says insertion order is not maintained. I have executed below code and for 10,000 times response is returned in same order. Also in key, I am just...
Jon Skeet
people
quotationmark

I have executed below code and for 10,000 times response is returned in same ordered. That's just what happens to occur with the version you're using and the values you're inserting. There's no guarantee it will continue to occur, or... more 1/20/2015 2:22:59 PM

people

Is it possible to unbox an object to more than one value type?

I have read in CLR via C#: Unboxing is really just the operation of obtaining a pointer to the raw value type (data fields) contained within an object. which means that if...
Jon Skeet
people
quotationmark

A boxed value can only be the boxed form of a single type - if you call o.GetType() you'll find out what that is. In general, you can only unbox to the exact same type, with a few wrinkles: You can unbox an enum value to its underlying... more 1/20/2015 2:18:31 PM

people

Can a java constructor have interfaces as arguments

I was experimenting with Java Interfaces, and the following code gave an error. In a class, a constructor takes Map as argument public class ClassA{ private...
Jon Skeet
people
quotationmark

I suspect you want to change Map<String,InterfaceA> to Map<String, ? extends InterfaceA> in the ClassA constructor signature (and field). Otherwise a HashMap<String, ImplmntsInterfaceA> really isn't a valid argument for... more 1/20/2015 10:32:37 AM

people