Browsing 7239 questions and answers with Jon Skeet

JSON format of result isn't correct

I have developed RESTful web service which is running fine I have used one POJO and one service class that is shown below but the issue is that in the output it is showing extra $...
Jon Skeet
people
quotationmark

Yes, this is the documented behaviour of Badgerfish: Text content of elements goes in the $ property of an object. From the documentation, there's no obvious way of transforming to object properties that don't have an @. (If you're... more 2/24/2018 10:43:52 AM

people

Why can't I replace IEnumerable<T> by a generic type variable in extension method?

I am trying to make an extension method more generic to avoid redundancy (Here is an example of some real code, the code below is just to demonstrate the issue - I had the idea to...
Jon Skeet
people
quotationmark

Why? For exactly the reason stated in the error message: you're trying to use IEnumerable<Customers> as the type argument for E, but E has this constraint: where E : System.Linq.IQueryable<T> And how can it be... more 2/22/2018 10:33:38 AM

people

What happens when you await a synchronous method

If I have a synchronous method "GetStrings()": private static Task<string[]> GetStrings(IEnumerable<int> ids) { var tasks = ids.Distinct().Select(GetString); ...
Jon Skeet
people
quotationmark

Task.WhenAll doesn't block anyway, unlike Task.WaitAll. It just return a task that completes when all of the original tasks have completed. It's important to understand that you don't await a method - you await a value (or some type that... more 2/21/2018 10:37:35 AM

people

XElement.Parse don't t allow to make a loop

My program builds an html file using XML. (I using System.Xml, using System.Xml.Linq). I would like to keep the form of the code in this way, but this solution does not work,...
Jon Skeet
people
quotationmark

Rather than building up a string, I'd suggest building up the XML directly: var body = new XElement("body"); using (SqlConnection conn = new SqlConnection(conString)) { string query = string.Format("{0}{1}'", "SELECT [VALUE1],[VALUE2]... more 2/21/2018 9:30:48 AM

people

DateTime Array interval

I want to create a DateTime Array wich counts 998 steps down from DateTime.now in 15 minute intervals wich should like the following Assuming the time is 20:00 {DateTime.now;...
Jon Skeet
people
quotationmark

I'd use LINQ for this, in combination with DateTime.AddMinutes. LINQ makes it very easy to generate a sequence, and then convert that sequence into an array: // Important: only call DateTime.Now once, so that all the values are //... more 2/20/2018 7:48:14 PM

people

String was not recognised as valid datetime for arabic language

I'm using below code for convert string to datetime(with slected language). It works well for all other language except Arabic. When passing ar as CultureInfo it throws an error...
Jon Skeet
people
quotationmark

The main problem is that the "ar" culture has a different default calendar system - it's trying to parse that as a date in the Um Al Qura calendar. If you print ci.DateTimeFormat.Calendar it will show System.Globalization.UmAlQuraCalendar,... more 2/20/2018 11:51:58 AM

people

LINQ ANY() with First() And FirstOrDefault()

I've written code like this TotalCashIn = totals != null && totals.Any() ? totals.First().TotalCashIn : null; And i have been blamed for this code and have told to...
Jon Skeet
people
quotationmark

You can use the null-conditional operator to make all of this a lot simpler, assuming that the element type of totals is a reference type: TotalCashIn = totals?.FirstOrDefault()?.TotalCashIn; With this: If totals is null, the overall... more 2/20/2018 7:55:09 AM

people

How to make a struct component a variable?

Not sure I am asking this right or this even possible. I feel to explain my question it is best to ask right in the code at the relevant places so please see my comments in the...
Jon Skeet
people
quotationmark

One option would be to have an array of extraction functions that you could apply to points. You can then use the LINQ Select overload that accepts a Func<TInput, int, TOutput> to generate a sequence of the values you want to add,... more 2/18/2018 3:57:08 PM

people

Creating a Guid > conversion from VB to C#

I have the following code in VB.Net and I'm trying to convert it to C#. listContacts = ACT_FRAMEWORK.Contacts.GetContactsByID(Nothing, New Guid() {New Guid(ContactID)}) Below...
Jon Skeet
people
quotationmark

Guid.NewGuid is a method, and you're not calling that method from your VB code - you're calling the constructor accepting a string. You can call that same constructor in C#: // Using an array initializer for simplicity Guid[] test = { new... more 2/13/2018 11:45:11 AM

people

Does Google.Protobuf support .NET Core?

I know from looking at the Google.Protobuf Git that there are some comments about .NET Core support but when I get a copy of the source code from Git the Google.Protobuf Project...
Jon Skeet
people
quotationmark

Google.Protobuf targets .NET 4.5 and netstandard1.0. It's important to understand that when multiple frameworks are listed in terms of dependencies, that just means that the package uses multi-targeting to support multiple... more 2/9/2018 7:08:52 PM

people