Browsing 7239 questions and answers with Jon Skeet

c# async without await

In documentation here: http://msdn.microsoft.com/en-us/library/hh191443.aspx it indicates that: If an async method doesn’t use an await operator to mark a suspension point,...
Jon Skeet
people
quotationmark

Yes, it's just a bad example. If ComputeNextMove is truly just a synchronous method which doesn't really do anything asynchronously (as the description suggests), it shouldn't be declared as async. It should instead be private void... more 2/11/2014 4:48:00 PM

people

Messagebox issue with If

I'm having weird behavior with my messagebox here is the code: private async void rate_Tap(object sender, System.Windows.Input.GestureEventArgs e) { string id =...
Jon Skeet
people
quotationmark

Your "else" block contains the code that you want to execute after you've checked all items - not on each item. I think you want: if (items.Any(item => item.itemid == id)) { MessageBox.Show("You already giving your rating."); ... more 2/11/2014 4:35:02 PM

people

save todays date to file name

Trying to include date into a filename when the file is written. DateTime todaysDate = DateTime.Now; string destFile = System.IO.Path.Combine(targetPath +...
Jon Skeet
people
quotationmark

I would suggest: Using a sortable date format, just because that's naturally pleasant Explicitly specifying the invariant culture, to avoid oddities of ending up using a different calendar system. (I suspect you always want to use the... more 2/11/2014 4:22:24 PM

people

Passing an array as `params` argument

I have the following method: void MyMethod(params object[] args) { } which I am trying to call with a parameter of type object[]: object[] myArgs =...
Jon Skeet
people
quotationmark

What you've described simply doesn't happen. The compiler does not create a wrapper array unless it needs to. Here's a short but complete program demonstrating this: using System; class Test { static void MyMethod(params object[]... more 2/11/2014 2:52:24 PM

people

how does compiler know that the class being used is a generic one although it has been compiled and its type erased to pre generic code

I understand that if I am using a generic method or generic class as a raw type and my code has not been compiled,the compiler warns me of using it as a raw type. But if i am...
Jon Skeet
people
quotationmark

Due to type erasure the .class file is purely pre-generic code and it must not be knowing whether it is generic or not No, that's not true. The information about the generic type is still present in the class file. Type erasure is... more 2/11/2014 2:24:56 PM

people

How do VB.NET anonymous types without key fields differ from C# anonymous types when compared?

I'm scratching my head about this as I cannot understand why the following happens the way it does: '//VB.NET Dim product1 = New With {.Name = "paperclips", .Price = 1.29} Dim...
Jon Skeet
people
quotationmark

In C#, all properties of anonymous types behave as if they have the Key modifier in VB: the properties are read-only, and they're included in equality and hash code evaluation. In VB, properties without the Key modifier are mutable, and... more 2/11/2014 1:52:33 PM

people

How can I get ByRef Arguments to work in a dynamically created assembly with Method.Invoke

I have a text file that I am compiling into an assembly use the VBCodeProvider class The file looks like this: Imports System Imports System.Data Imports...
Jon Skeet
people
quotationmark

However comment is always "Foo" (message box shows "Not Allowed"), so it appears that the ByRef modifier is not working It is, but you're using it incorrectly, with incorrect expectations :) When you create the argument array, you're... more 2/11/2014 12:04:00 PM

people

Why does this java regular expression not work?

Why does this Pattern not match the port in my URL? public class PatternTest { private Pattern PORT_STRING_PATTERN = Pattern.compile(":\\d+/"); private boolean...
Jon Skeet
people
quotationmark

The problem is that you're using Matcher.matches(), which is documented as: Attempts to match the entire region against the pattern. You don't want to match the entire region - you just want to find a match within the region. I... more 2/11/2014 10:24:12 AM

people

How to myList.addAll(newList) will put new items of newList to top & push the existing items of myList to the bottom?

Does any one know a very simple method to do that. Ex: List<String[]> myList=new ArrayList<String[]>(); myList.add(s1); myList.add(s2); List<String[]>...
Jon Skeet
people
quotationmark

Just use the overload of addAll which takes the index at which to insert the items: myList.addAll(0, newList); No need for a new method at all. more 2/11/2014 9:25:04 AM

people

How are arrays of strings stored in memory

I'm trying to see how much memory is used when I have a lot of duplicate strings. I am using the method highlighted in this answer (at the bottom) Here's me creating a list of a...
Jon Skeet
people
quotationmark

Your List<String> isn't storing strings. It's storing string references. In each case, you've got a single String object, and then a list with a lot of references to the same object. It's like having a single house, and millions of... more 2/10/2014 10:11:54 PM

people