Browsing 7239 questions and answers with Jon Skeet

Effects of using multiple awaits in the same method?

I have the following method which commits changes to a db (using Entity Framework): public async Task<int> CommitAsync(Info info) { if (this.Database.Connection.State...
Jon Skeet
people
quotationmark

It's absolutely fine to have multiple await expressions in the same async method - it would be relatively useless feature otherwise. Basically, the method will execute synchronously until it reaches the first await where the awaitable... more 5/2/2016 7:12:00 AM

people

JodaTime doesn't fail on mismatched day of week and month

In the following piece of code, I expected an exception to be thrown because the day of week doesn't match the day of month. I couldn't find anything in the DateTimeFormat...
Jon Skeet
people
quotationmark

You're right, it does - as documented (emphasis mine): Parsing builds up the resultant instant by 'setting' the value of each parsed field from largest to smallest onto an initial instant, typically 1970-01-01T00:00Z. This design means... more 5/1/2016 11:46:51 AM

people

C# Why are some of these methods using delegates and generics not starting?

I was trying to learn a bit about generics and the SelectMany function and delegates. The semantic function of the code below(as in what the functions are supposed to be doing),...
Jon Skeet
people
quotationmark

Those methods are iterators - they use yield return. They execute in a special way... the code only gets executed as you iterate over the result. So if you change the calling code to: foreach (var item in _SelectManyIteratora) { } then... more 5/1/2016 7:43:27 AM

people

Can't access variables on a json class. C#

I recently tried using the twitch json api, i never had experience with json so it was a nice challenge but then i used json2csharp.com and converted a json string to a class like...
Jon Skeet
people
quotationmark

Stream is the name of a class within TwitchAPI - you haven't declared any fields within the TwitchAPI class at all, as far as we can see. So you could use: TwitchAPI.Stream stream = new TwitchAPI.Stream(); string viewers =... more 4/30/2016 3:21:22 PM

people

C# Mysql Does not update

The Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Default=0 WHERE Default=1 AND...
Jon Skeet
people
quotationmark

I suspect the problem is that DEFAULT is a reserved word. Ideally, change your schema to avoid using reserved words as field names. Alternatively, quote the name: UPDATE user_inventory SET `Default`=0 WHERE `Default`=1 AND UserID=@oid more 4/30/2016 9:20:32 AM

people

Create a view in bigquery with date rounded down to midnight?

I am creating a view in BigQuery with the following SQL statement: SELECT Id, CreatedDate FROM [bucketname.tablename] How can I modify this query so that the CreatedDate becomes...
Jon Skeet
people
quotationmark

I believe you can just use the DATE function: Returns a human-readable string of a TIMESTAMP data type in the format %Y-%m-%d. So: SELECT Id, DATE(CreatedDate) AS CreatedDate From [dataset.tablename] more 4/30/2016 6:55:59 AM

people

Creating generic method

Can someone please help with the following... it's driving me nuts... // Three methods, virtually identical with the exception of the select field public IEnumerable<int>...
Jon Skeet
people
quotationmark

It sounds like you probably just want a Func<Model, int> parameter: public IEnumerable<int> GetData(Func<Model, int> projection) { return myData.Select(projection).Distinct(); } You could then have: var modelIds =... more 4/28/2016 10:51:44 AM

people

c# linq to xml update all descendants of specific value

I am creating a configuration file editor, and am currently implementing features for updating existing data. I would like to be able to update all attributes within the file...
Jon Skeet
people
quotationmark

Currently you're trying to fetch the value for the user attribute of every element in the document - including the root element, for example. Two options here, which I'd probably use both of: Specify that you only want user elements,... more 4/27/2016 9:11:20 PM

people

Lambda expression to initialize array

Is there a way to initialize an array or a collection by using a simple lambda expression? Something like // What about this? Person[] persons = new Person[15]; persons = ()...
Jon Skeet
people
quotationmark

Sure - I don't know how useful it is, but it's certainly doable: import java.util.*; import java.util.function.*; import java.util.stream.*; public class Test { public static void main(String[] args) { ... more 4/27/2016 9:22:01 AM

people

Two Dimensional Array Declaration and Initialisation in Java

String[][] twoD3; twoD3 = {{"1234", "5435", "2345"}, {"pebbles"}}; What is the problem with the above array initialization? Why am I getting compile error? The error is: ...
Jon Skeet
people
quotationmark

This has nothing to do with it being an array of arrays. You'll see the same error with this simpler code with a single array: String[] array; array = { "foo", "bar" }; You can't do that - an array initializer can only be used on its... more 4/26/2016 8:56:50 PM

people