Browsing 7239 questions and answers with Jon Skeet

How to group list of objects, which contains another list?

I have a class with these properties: public string FirstName { get; set; } public string LastName { get; set; } public int ID { get; set; } public GradeLevel Year; public...
Jon Skeet
people
quotationmark

It sounds like you want to create a sequence of student/mark pairs, and then group by the mark: var studentsByMark = from student in students from mark in student.ExamScores group student by... more 12/7/2015 4:31:10 PM

people

C# equivalent of a Java class with multiple Setter methods

I am trying to write a C# version of a Java class. If we call our class MyRequest, we are dealing with a field called _body which is a JSONObject. Here is a simplified version of...
Jon Skeet
people
quotationmark

I would normally have a property with the same type as you want to expose with the getter, and then have additional SetBody methods. So potentially: private JObject body; public string Body { get { return body.ToString(); } set {... more 12/7/2015 12:58:16 PM

people

Datetime implicit conversion to Datetimeoffset results in incorrect offset?

I noticed something odd when trying to determine if a given datetimeoffset occurred on the beginning or end of a timezoneadjustment (daylight savings). And I'm not sure if I'm...
Jon Skeet
people
quotationmark

Firstly, GetDaylightChanges is accurate - the clocks did go back in Sweden at 3am local time. Secondly, that doesn't mean that you've shown a bug anywhere in the BCL. The problem is simply that 02:00:00 occurs twice - once before the... more 12/7/2015 9:25:44 AM

people

Xml doesn't save to file

I writing Android app in Xamarin I have xml that is writing to file (realized) On different Activity I try to open this file , replace some strings and save Open file like...
Jon Skeet
people
quotationmark

You haven't modified the document. You've asked the document for a string representation of itself, then assigned a new string to the same variable - but that doesn't change the XML in the document at all. I would strongly urge you to use... more 12/7/2015 8:33:16 AM

people

Backgroundworker exits after first expression

I have a list view bound to an ObservableCollection. With that I want to mock a chat application with a WPF gui. To simulate some activity I wanted to use a Background worker who...
Jon Skeet
people
quotationmark

Yes, you're modifying the UI (indirectly, through the ObservableCollection<>) on a non-UI thread. You're not allowed to do that. I suspect you should find an exception being thrown giving that detail, although it may not be easy to... more 12/7/2015 7:18:56 AM

people

ObjectOutputStream: appending question marks at the beginning of the String

Server(Java) sends a Json String to a client(TypeScript). On the client I get the following: Therefore JSON.parse() fails due to question marks being appended. I...
Jon Skeet
people
quotationmark

Basically, you shouldn't be using ObjectOutputStream if you're just trying to send text. That's not what it's for. ObjectOutputStream performs binary serialization in a Java-specific format, of arbitrary serializable objects. It should... more 12/7/2015 6:59:29 AM

people

Decimal not showing group(thousand) separator after parse

In console application I've created 2 decimals: using literal value using a string parse I've set my culture to "en-GB" System.Threading.Thread.CurrentThread.CurrentCulture =...
Jon Skeet
people
quotationmark

This is the problem: Console.WriteLine("Decimal value Converted: " + moneyConversion); //-34555.897 You're using moneyConversion (the decimal value) rather than moneyConversionString. If you change it to: Console.WriteLine("Decimal... more 12/5/2015 11:32:03 PM

people

How object with members that are not specified in class be created?

Picture below shows a MSDN reference of RouteCollectionExtensions.Maproute method. The method have 1 parameter called defaults which is an object type. Picture below shows a...
Jon Skeet
people
quotationmark

There are various separate ideas you need to understand here. Most importantly, there's the idea of an anonymous type. Look at this: var x = new { Name = "Jon", Location = "Reading" }; That has created an instance of an anonymous type,... more 12/4/2015 11:48:30 AM

people

JsonConvert help reading from file

I am trying to read from this json file, The problem is that I am not getting any info back, also 1357 is always changing. This is part of the file { "result": { ...
Jon Skeet
people
quotationmark

The problem is that you've got the extra "layer" between the result property and the object with Random and Random2. It looks like you want something like: class ReadRandomResult { public Dictionary<string, ReadRandom> Result {... more 12/4/2015 9:31:21 AM

people

How to typecast single element of List<double> as type 'double' in calculation in C#

Suppose I have an initialized list: List<double> o I'd like to perform the following: int offset = 10; for (int i = 0; i < o.Count; ++i){ o[i] =...
Jon Skeet
people
quotationmark

There are four problems here: You have to use ref on the argument as well as the parameter The expression o[i] - offset is classified as a value rather than a variable, so you can't pass it by reference Even the expression o[i] would be... more 12/4/2015 7:29:14 AM

people