Browsing 7239 questions and answers with Jon Skeet

Why do I get no additional MessageBoxes?

namespace övning_2._2_mitt_första_program { public partial class Form1 : Form { public Form1() { InitializeComponent(); } ...
Jon Skeet
people
quotationmark

You're currently using the Form.DialogResult property of the current instance of Form1, instead of your dialogResult variable obtained from the message box. This: if ( DialogResult == DialogResult.No) should be: if (dialogResult ==... more 1/15/2014 1:23:06 PM

people

Thread.sleep within for loop causing issue with loop body

So in the code posted below I have a for loop which iterates 10 times, the goal of the for loop is to create the same ImageView 10 times every .5 seconds. When I tested this, it...
Jon Skeet
people
quotationmark

Thing is, why does it wait the 500ms 10 times in the loop THEN do the rest of everything in the for loop. It doesn't. It executes the iterations of the loop, once every 500ms - and then you allow the UI thread to actually display the... more 1/15/2014 1:12:15 PM

people

How to use getDeclaredConstructor if my constructor accepts a primitive type?

I am finding a constructor like this: type.getDeclaredConstructor(Integer.class); This works when type is MyType { public MyType(Integer a); } However, this does not work...
Jon Skeet
people
quotationmark

You can use type.getDeclaredConstructor(int.class); From section 15.8.2 of the JLS: A class literal is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type void, followed by a '.'... more 1/15/2014 10:33:06 AM

people

Providing a field accessor method as an argument

G'day comrades. I have a problem. I have two methods which are completely duplicate apart from that they are accessing a different field. I cannot pass the field value as a...
Jon Skeet
people
quotationmark

Well, you could have something like: public interface Function<In, Out> { Out apply(In input); } Then: public int getCount(Function<Box, Integer> projection) { int total = 0; for (Box box : boxes) { ... more 1/15/2014 10:28:28 AM

people

Why is the button in an offset position

Here is the code: Dim nBtn As New Button PictureBox1.Controls.Add(nBtn) nBtn.Text = "Click Me" nBtn.Location = Cursor.Position ' or mouseposition = same result ...
Jon Skeet
people
quotationmark

Control.Location refers to the location relative to the control's container (or rather, its top-left point). Cursor.Position (and Control.MousePosition) refer to a location relative to the top-left corner of the screen. So if your... more 1/15/2014 7:14:31 AM

people

Arrays.asList().contains() on Double vs double arrays

I have a double array doubleArray1. I tried a Arrays.asList().contains() operation as shown below double doubleArray1 [] =...
Jon Skeet
people
quotationmark

Your first call to Arrays.asList is actually returning a List<double[]> - it's autoboxing the argument, because a double[] isn't a T[]... generics don't allow for primitive types as type arguments. If you want to convert a double[]... more 1/14/2014 5:59:01 PM

people

Does try catch share the same scoping block?

I have a try-catch sequence. try { int tryCatchVar = 0 ...other code... } catch { if (tryCatchVar != 0) return; } I declared and assigned a variable in the try...
Jon Skeet
people
quotationmark

However, because of the strong relational aspect of try-catch, I am wondering if the variable declared in try is in scope for catch? You can test this easily for yourself, but the answer is no. (Second part) Would that... more 1/14/2014 5:57:03 PM

people

WPF Thread with Join() blocks UI thread

My main class: List<string> myList; ... private void Button_Click(object sender, RoutedEventArgs e) { Thread thread = new Thread(() => { myList =...
Jon Skeet
people
quotationmark

Make your thread call back to the UI to set the ItemsSource: private void Button_Click(object sender, RoutedEventArgs e) { Thread thread = new Thread(() => { myList = myClass.getListData(); Action uiAction = ()... more 1/14/2014 5:02:34 PM

people

Covariant use of generic Lazy class in C#

Assuming that this applies: public class Cat : Animal { } and assuming that I have a method: public void Feed(Animal animal) { ... } And I can call it this way: var animal...
Jon Skeet
people
quotationmark

You can't, basically - not directly, anyway. Lazy<T> is a class, so doesn't suppose generic variance. You could create your own ILazy<out T> interface, implement it using Lazy<T>, and then make Feed take... more 1/14/2014 3:46:17 PM

people

Why does it required UAC for changing files?

I creted an application that has ini file and db.mdb (access) and it downloads some images from web to a folder that is near of App. Well, I created a setup file with Setup...
Jon Skeet
people
quotationmark

You're trying to modify a file within Program Files. That's an area of the file system which isn't designed for mutable application data - it's basically meant to be read-only. Modifications to this area are suspect, hence the UAC... more 1/14/2014 1:43:50 PM

people