Browsing 7239 questions and answers with Jon Skeet

Is there a java Set collection which ignores .equals

I'm doing something weird. I want to create a Set, but I want to ignore the equals override on those objects, instead I want to do obj1 == obj2 for the equals comparison...
Jon Skeet
people
quotationmark

You could use IdentityHashMap and just ignore the values (the keys will form a set). There are various implementations of IdentityHashSet available online, too. You could use Guava, for example, with... more 12/31/2013 6:38:46 PM

people

Reference to an object of any class that implements two or more given interfaces

Given any interface I, it is possible to declare a variable that holds a reference to any object of a class C that implements I: I i = new C(); I want to do something similar....
Jon Skeet
people
quotationmark

Given two interfaces, I want to declare a variable that holds a reference to any object of a class that implements both interfaces Unfortunately you can't do that. You can do so for a parameter in a generic method, like this: public... more 12/31/2013 5:19:58 PM

people

How do i add dll file to my project forever?

I have this code in constructor: InitializeComponent(); textBox3_text_valid = 0; label8.Visible = false; label8.Visible = false; ...
Jon Skeet
people
quotationmark

The problem is that the dll is in my debug directory. Don't do that then. I would suggest you create a lib directory or something like that, and add a reference to the library from there. By default, that will copy it when you build... more 12/31/2013 5:14:50 PM

people

What happen if I delete App.config in C# application?

I write a small application, that I don't need store anything in config files. So the file App.config in my source is exactly what ever Visual Studio has created. So I want to...
Jon Skeet
people
quotationmark

I wonder if I delete App.config file, then copy my application to other pc, is it have any strange behavior? Nope, it should be fine. There are various (somewhat tortuous) rules about exactly what version of the CLR etc gets used in... more 12/31/2013 4:30:22 PM

people

Unable to retrieve Distinct record from database?

I have a Database table like below, ID Author Book 1 Kate Smuggler 2 Harper Smuggler 3 Slater Smuggler 4 Kate Katy 5 Smitha Katy i want to retrieve all Book...
Jon Skeet
people
quotationmark

This part: select s.Book is selecting just the book (title) part of the record. You can't get back from that to the ID... there can easily be multiple IDs for the same title, as per your sample data. It's not clear what you'd want that... more 12/31/2013 4:19:37 PM

people

How to initialiaze a unsigned byte array with a set of well known values in Java 7?

I want to initialize a byte array with unsigned byte values ranging from 0 to 255. Here is how I did it: int N = 256; char[] tmp = new char[N]; for (char c = 0; c < N; c++)...
Jon Skeet
people
quotationmark

Why is there a bunch of 3F ? Why can't I get 80, 81 ... after 7F ? Because your character array contains non-ASCII characters. Charset.encode is encoding those as 3F (ASCII for '?') to represent the fact that they're not in... more 12/31/2013 3:55:36 PM

people

Using Moq to mock an asynchronous method for a unit test

I am testing a method for a service that makes a Web API call. Using a normal HttpClient works fine for unit tests if I also run the web service (located in another project in the...
Jon Skeet
people
quotationmark

You're creating a task but never starting it, so it's never completing. However, don't just start the task - instead, change to using Task.FromResult<TResult> which will give you a task which has already... more 12/31/2013 3:47:55 PM

people

More elegant way of defining array contents

I am trying to define the contents of an array. A way of achieving what I want is shown below for a simplified example. Is there a better way of doing it? This seems like a...
Jon Skeet
people
quotationmark

You can create one array with all the options, and then just copy as many as you need: // This declaration could be for a private static readonly variable, given that // you won't change the contents string[] allBoxes = { "Blue box", "Red... more 12/31/2013 10:43:46 AM

people

CompileAssemblyFromSource comments

my c# script contains some fields with commetns , when i use the CodeDomProvider to compile it , everything is great but when i look at the code i see there is no comments...
Jon Skeet
people
quotationmark

You won't get non-XML comments anyway - they're never part of the result of compilation. However, you can generate the XML documentation file using the CompilerOptions property to just pass a command-line parameter to the... more 12/31/2013 9:08:00 AM

people

Is a dirty read from memory possible when multi threading?

In this case, I define dirty read as reading from memory when it's currently being written to by another thread. So if thread #1 writes 100 to a variable that thread #2 can also...
Jon Skeet
people
quotationmark

You're actually trying to rely on several different things here. Firstly, there's the matter of atomicity. ECMA-335 states: A conforming CLI shall guarantee that read and write access to properly aligned memory locations no larger... more 12/31/2013 8:41:36 AM

people