Browsing 7239 questions and answers with Jon Skeet

set a (method) breakpoint for a particular object (and not all instances of that type) in java

Suppose I have a class public class Foo { public void doThing() { ...} } Say I have a lot instances of Foo, but I'm only particularly interested in one of them. How would...
Jon Skeet
people
quotationmark

I don't know of any "proper" way, but one approach would be to call hashCode() in the watch window when you first create it, and then make the breakpoint conditional on the hashCode() as well. So you'd need to change the break point each... more 1/24/2015 9:58:19 PM

people

Is it ok to put a main() function in all modules for the purpose of unit tests?

I have several subclasses to go along with my main class. Is it bad practice to add a main function to every single class for tests?
Jon Skeet
people
quotationmark

Is it bad practice to add a main function to every single class for tests? Yes, for various reasons: It suggests you've got a single test per class, or multiple tests within a single method. It suggests you're probably not using a... more 1/24/2015 6:58:45 PM

people

Covert C# Datetime to MySql DateTime format

I have been trying to figure out how to add current datetime from c# into mysql column and that attribute/column is also in 'datetime' format. I am writing this code. if...
Jon Skeet
people
quotationmark

The right answer is to stop building your SQL like that to start with. Use parameterized SQL, then specify the DateTime value as the parameter value - you don't need a string representation at all in your code. It's not immediately clear... more 1/24/2015 6:56:35 PM

people

Object oriented programming: Method Capabilities

I'm sorry for, maybe, repeating the same question once again, but I'm lost and don't know where to go. After tons of googling and RTFMing everything I can find on methods I still...
Jon Skeet
people
quotationmark

For example: I have a method that calculates a bunch of results from 2 long variables That sounds like you should encapsulate the results in a new class then, and use method parameters for the two inputs. Any time you have multiple... more 1/24/2015 11:08:33 AM

people

How to Call method with arguments coming from a hashset?

static public void Configure( Activity activity,String client_options, String app_id, String... zone_ids ) I have this hashset that contains up to 500 elements. How...
Jon Skeet
people
quotationmark

Unfortunately, you'd need to convert the set to an array - it's easy to do, but quite inefficient: Configure(activity, options, appId, zoneIdSet.toArray(new String[0])); The new String[0] could be replaced by new... more 1/24/2015 10:32:28 AM

people

java: why this binarySearch with comparator is not working?

Updated: I am trying to use Collections.sort() to sort an arrayList with a comparator parameter. Then do binarysearch. package collection; import java.util.*; public class...
Jon Skeet
people
quotationmark

Binary search only works when the list is already sorted. The way that binary search works is that the algorithm assumes that if the value at its "guess" index is higher than the one we're looking for, the actual index must be lower - and... more 1/23/2015 8:52:04 PM

people

Moving away from primary constructors

The C# 6 preview for Visual Studio 2013 supported a primary constructors feature that the team has decided will not make it into the final release. Unfortunately, my team...
Jon Skeet
people
quotationmark

As I suggested in comments, you could use the version of Roslyn which does know about primary constructors to parse the code into a syntax tree, then modify that syntax tree to use a "normal" constructor instead. You'd need to put all the... more 1/23/2015 4:35:09 PM

people

Can't target .net 3.5 after Windows update

All of my builds broke after one of the updates this week. Now I can't change the target framework and I can only choose 4.0 system assemblies Is there any way I can get around...
Jon Skeet
people
quotationmark

Look at the .NET Framework Targeting Pack page for issues like this. Basically, under Windows 8 you need to explicitly enable .NET 3.5 in "Windows Features". For earlier versions of Windows it just needs to be installed - the page has a... more 1/23/2015 4:03:10 PM

people

Can't see properties from interface

I'm having some interface woes! Here's the code: I expected to be able to access the properties Added and ID through my test template, but intellisense says No! Am I misusing...
Jon Skeet
people
quotationmark

This is the problem: public class TestTemplate<ITrackedItem> You've declared a type parameter called ITrackedItem, which is entirely different to the ITrackedItem interface. It's not clear that your type needs to be generic at all... more 1/23/2015 11:55:24 AM

people

Should passwords be compared culture specific or binary equal?

As everyone knows there are different ways to compare strings in unicode. One of them is culture specific. This is a well worked out topic in .Net, too. I am currently in the...
Jon Skeet
people
quotationmark

It should match the equality that will be tested for the hashed version. Basically, imagine that one of the passwords was stored, and you were trying to log in with the other - would it work? That's surely what you're trying to test. I'd... more 1/23/2015 11:34:25 AM

people