Browsing 7239 questions and answers with Jon Skeet

Compilation Error does not have the same signature as delegate

Not sure what I am doing wrong... BC30408: Method 'Protected Sub ValidateUser(sender As Object, e As System.EventArgs)' does not have the same signature as delegate ...
Jon Skeet
people
quotationmark

A clue lies before your error message: Microsoft (R) Visual Basic Compiler version 8.0.50727.5420 for Microsoft (R) .NET Framework version 2.0.50727.5420 Copyright (c) Microsoft Corporation. All rights reserved. That's an ancient... more 5/30/2016 7:16:15 AM

people

Use Values and Range Attribute in NUnit TestFixture constructor

I have multiple test methods which should test all possible combinations of multiple parameters. I can use the NUnit ValueAttribute or RangeAttribute on methods like...
Jon Skeet
people
quotationmark

You can use ValuesSource: [Test] public void TestedEntity_GivenParemeter_Passes( [ValueSource(nameof(FirstSource))] int inputA, [ValueSource(nameof(SecondSource))] int inputB) { if (inputA > 0 && inputB > 0) ... more 5/29/2016 11:46:37 AM

people

No overload for method move

So basically, I have a process that starts from user input in a textbox. But one of the arguments in the process contains a folder which the user has but has the be renamed. and...
Jon Skeet
people
quotationmark

Yes, you're calling Directory.Move, which only has one overload, with two string parameters. It's not clear why/how you expected that to work. I suspect you're missing calls to string.Format, e.g. string source =... more 5/29/2016 11:27:49 AM

people

Java How to know what has been eliminated HashSet?

How to know what has been eliminated HashSet ? I have an array int [] x = {2, 4, 4, 5}; When I covert it, HashSet<Integer> set = new...
Jon Skeet
people
quotationmark

Instead of using that constructor, you could use: Set<Integer> set = new HashSet<>(); for (int value : x) { if (!set.add(value)) { // Or whatever you want to do System.out.println("Detected a duplicate... "... more 5/29/2016 9:43:30 AM

people

When executor meets Thread.sleep, why the thread ends without sleeping or throw InterruptedException?

I do not know why junit has the following behavior: When I submit a thread into a executor (fixedThreadPool or others) while the thread has a sleep behavior (Thread.sleep()), I...
Jon Skeet
people
quotationmark

Yes, because you're not waiting for the tasks you've scheduled to complete. If you have other unit tests, the threads you've created will still keep executing in the background, but your test will complete because you've not told it to do... more 5/29/2016 9:25:06 AM

people

Should I declare an unchecked exception?

I've got a method which invokes another method like this: public void m1() { m2(10); } public void m2(int v) { if(v < 10) throw new MyException(); } public...
Jon Skeet
people
quotationmark

You can do so - and it'll show up in the Javadoc, I believe. But it won't force any callers to handle the exception, so you're still basically relying on the users (developers calling your code) to be diligent enough to check the... more 5/29/2016 7:24:22 AM

people

Does async Task method never throw?

It appears that an async method always captures its exceptions into a Task that the method returns including those thrown before the first await". In other words the following...
Jon Skeet
people
quotationmark

Is this behavior of async methods part of the language spec Yes it is. From section 10.15.1 of the C# 5 specification: If the function body terminates as the result of an uncaught exception (ยง8.9.5) the exception is recorded in... more 5/28/2016 7:28:13 PM

people

Enumeration type in c#

When we create variable of enumeration type and assign it an enumeration value enum Members{HighlyQualified, Qualified, Ordinary} class { static void Main() { Members...
Jon Skeet
people
quotationmark

Here we are clear that the value of developers is string which reference to the memory location of characters. No, it's not. The value of developers is of type Members. It's converted to a string by the Console.WriteLine method.... more 5/28/2016 9:40:27 AM

people

Mechanism of Unboxing

When unboxing takes place there is the copy of boxed value into an appropriate variable type but what happens at the memory location of the boxed copy on heap. Is boxed copy...
Jon Skeet
people
quotationmark

Is boxed copy remain at that location and cover memory on heap? Yes. After all, there could be other references to it: object o1 = 5; object o2 = o1; int x = (int) o1; x = 10; Console.WriteLine(o2); // Still 5 Boxed values act like... more 5/27/2016 4:52:13 PM

people

Deserializing the Json object to .NET object

I have following JSON object returned by vatlayer api { "success":true, "rates":{ "AT":{ "country_name":"Austria", "standard_rate":20, ...
Jon Skeet
people
quotationmark

Just model the response like this: public class Response { public bool Success { get; set; } public Dictionary<string, Country> Rates { get; set; } } Then: var response =... more 5/27/2016 1:48:27 PM

people