Browsing 7239 questions and answers with Jon Skeet

Linq group by ID and then sum the ID itself (key)

I have two lists which are basically of the same class type like following: public class TransactionsTabResults { public string ItemID { get; set; } public string...
Jon Skeet
people
quotationmark

You don't want to "sum the IDs" - you just need the average of the prices, which you can get using the Average method. If you want the count, just call Count(): AverageRevenuePerItem = pr.Average(y => y.ItemPrice), TotalSalesPerItem =... more 11/26/2016 6:35:21 PM

people

Incrementing and Decrementing Confusion

I am a little confused about the following behaviour: int a = 3; a++; in b = a; I understand that when you do a++ it will add a 1 which makes a = 4 and now b equals a so they...
Jon Skeet
people
quotationmark

This line: int d = c; says "Declare a variable called d, of type int, and make its initial value equal to the current value of d." It doesn't declare a permanent connection between d and c. It just uses the current value of c for the... more 11/26/2016 9:12:56 AM

people

Work with double quotes and parameter adding to a query

Original Query which I can run positive in PgAdminIII: SELECT * FROM oestrat."Themenfeld" oestrat and Themenfeld are strings coming from Winform textboxes. So my query in VS...
Jon Skeet
people
quotationmark

I don't believe you can specify table names as parameters... only values can be specified as parameters. Instead, either have a white-list of permitted table names, or at least a white-list of permitted characters within table names,... more 11/25/2016 4:41:32 PM

people

How do you parse date String in the form "Nov 17, 2016 7:26:57 PM" into Date?

I tried the following pattern with new SimpleDateFormat(pattern).parse("Nov 17, 2016 7:26:57 PM") but none of them work: MMM d, yyyy h:m:s a MMM dd, yyyy HH:mm:ss a MMM dd, yyyy...
Jon Skeet
people
quotationmark

You need to: Make sure the pattern is right Specify the right locale In this case, you want an English locale for English month names: SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy h:mm:ss a", Locale.ENGLISH); Note that... more 11/25/2016 12:37:11 PM

people

XElement.Decendents.First not finding xml field

I'm trying to read an XML file and find the value of a field. I am reading from file "MyMessage.txt": <?xml version="1.0" encoding="UTF-8"?> <Document...
Jon Skeet
people
quotationmark

You're looking for an element called TxId in no namespace - but your element is implicitly in the "urn:com.company:request.001" namespace, which is inherited from its ancestor. So you need: element.Descendants(ns + "TxId").First() more 11/24/2016 3:45:52 PM

people

C# Best Practice What is the best practice when converting int? to int

I have a nullable int coming in from the database from a stored procedure that I know will not have a null value. I have done the bellow: public List<EngineerDetails>...
Jon Skeet
people
quotationmark

An InvalidOperationException will be thrown if s.CurrentJobId is actually null anyway. That's almost always the best outcome for situations of "the world is not the way I expect it to be" so it makes sense to use the code exactly as-is. more 11/24/2016 11:35:15 AM

people

T type default value

I had several Extension Methods like ParseInt, ParseLong, ParseByte. now I'm trying to make a single extension method for all of them. the problem is that to make the Default...
Jon Skeet
people
quotationmark

You can just use default(T) instead: public static T Parse<T>(this string x, T defaultValue = default(T)) However, I would strongly question the design here - you're not really writing a generic method, but a method which accepts... more 11/23/2016 9:46:33 PM

people

Google Natural Language API with Java setLanguage

I am using the Google Natural Language API to analyze entities from different texts. Is there a way to change the language of the input text to, for example english, as it is the...
Jon Skeet
people
quotationmark

You specify the language via the relevant ISO or BCP-47 tag in the Document part of the request. So for example: Document document = Document.newBuilder() .setLanguage("en") .set... // Call other setters .build(); more 11/23/2016 1:53:48 PM

people

What is the difference between Google Compute Engine, App Engine and Container Engine in Google Cloud?

What is the actual difference between Google Compute Engine, App Engine and Container Engine in Google Cloud Compute? When to use what? Is there any good example to understand...
Jon Skeet
people
quotationmark

(Disclaimer: I work in the Google Cloud Platform team, but this is a personal answer.) All of these are solutions which allow you to host your applications in the cloud. You can view them as a sort of spectrum of control/automatic... more 11/23/2016 11:05:33 AM

people

Windows store app .NET GetCurrentMethod().DeclaringType alternative

quite stuck with this one... I have this problem where we are using log4Net in a Unity project for building a Windows store app. log4Net needs either the classes type or name (as...
Jon Skeet
people
quotationmark

Just use typeof instead - it's much simpler, and doesn't require any framework support: public sealed class SomeClassController : ApiController { private static readonly ILog Log = ... more 11/23/2016 8:30:00 AM

people