Browsing 7239 questions and answers with Jon Skeet

Extract from Timespan Totalhours and Minutes

I get from TimeSpan.TotalHours 24,75 hours. How can I convert this to get the full and not roundes hours (=24) plus the minutes (0,75hours = 45 minutes)? So the result should be...
Jon Skeet
people
quotationmark

Well just round the total hours appropriately by casting, and then use the Minutes property: int hours = (int) timeSpan.TotalHours; int minutes = timeSpan.Minutes; If you'll ever have a negative TimeSpan, you should think about what you... more 3/23/2016 12:42:37 PM

people

Must type multiple times, before scanner reads input

If I run this code Scanner sc = new Scanner(); while (true) { if (sc.next().equals("1")) System.out.println("--1--"); else if...
Jon Skeet
people
quotationmark

You're calling sc.next() multiple times - so if the input isn't 1, it's going to wait for more input to see whether the next input is 2, etc. Each call to sc.next() will wait for more input. It doesn't have any idea of "that isn't the... more 3/23/2016 11:50:52 AM

people

C# All Check box Appearance

In my WinForms Visual Studio application i have a checkbox styled as a Flat Button with this C# code: private void checkBox1_CheckedChanged(object sender, EventArgs e) { ...
Jon Skeet
people
quotationmark

If you want multiple controls to use the same eventhandler, that's easy - just use the same event handler. Change your code to something like: private void HandleCheckBoxCheckedChanged(object sender, EventArgs e) { CheckBox checkBox =... more 3/23/2016 7:16:57 AM

people

removing the root element in xml in java

removing the root element in xml in java
Jon Skeet
people
quotationmark

It sounds like you just want to replace the root element with its single child, right? So you want: XDocument doc = XDocument.Load(@"C:\Users\ADMIN\Pictures\sample.xml"); doc.Root.ReplaceWith(doc.Root.Elements().Single()); That's all... more 3/22/2016 6:15:42 PM

people

Why does conversion between GregorianCalendar and OffsetDateTime fail when evaluating the ZoneInfo part?

I am converting an OffsetDateTime to a GregorianCalendar as part of populating values for an outbound web service. I just thought I'd test the actual conversion. It is failing...
Jon Skeet
people
quotationmark

Basically, as far as I'm aware, java.time doesn't try to model a Gregorian cutover - so when an OffsetDateTime is converted back to a GregorianCalendar, that's done by modeling it as having a Gregorian calendar with a cutover back at the... more 3/22/2016 5:53:44 PM

people

IEnumerable<type> does not contain a definition of 'Contains'

I have 2 classes and 2 IEnumerable lists of those classes: public class Values { public int value {get;set;} public DateTime someDate {get;set;} } public class...
Jon Skeet
people
quotationmark

As an alternative to what everyone else has suggested already: var holidayDates = new HashSet<DateTime>(holidays.Select(h => h.holiday)); var query = values.Where(x => !holidayDates.Contains(x.someDate)); In particular, if... more 3/22/2016 4:14:40 PM

people

XDocument does not return the expected node

I try to work with the XDocument in C# but have some problems to receive the desired elements. Here is my sample xml <?xml version="1.0" encoding="UTF-8"?> <xfdf...
Jon Skeet
people
quotationmark

You don't have a fields element which isn't in a namespace, which is what you're asking for. Due to this in the root element: xmlns="http://ns.adobe.com/xfdf/" ... the default namespace URI for the descendant nodes is... more 3/22/2016 3:46:21 PM

people

How to convert a dynamic list into list<Class>?

I'm trying to convert a dynamic list into a list of class-model(Products). This is how my method looks like: public List<Products> ConvertToProducts(List<dynamic>...
Jon Skeet
people
quotationmark

You're currently trying to get properties from data, which is your list - and you're ignoring x, which is the item in the list. I suspect you want: var sendModel = data .Select(x => new Products { Name = x.Name, Price = x.Price }) ... more 3/22/2016 9:02:46 AM

people

Create a list of attribute of nested nodes from XML file

I have an XML file as following: <?xml version="1.0" encoding="utf-8"?> <files> <file name="1"> <file name="4"> </file> ...
Jon Skeet
people
quotationmark

It seems that you possibly want: For all file elements which don't have a child file element Work out the file element ancestry Take the name attribute for each ancestor, and join it together So I think this should work, creating an... more 3/22/2016 8:30:27 AM

people

Incompatible Map Entry with ENUm in java

Why am i getting "The return type is incompatible with Map.Entry<SEND,CANDataSendInfo>.getKey()" Here i am trying to make object which consist of enum as key and Class...
Jon Skeet
people
quotationmark

This is the problem: public class SendKV<SEND , CANDataSendInfo> implements Map.Entry<SEND , CANDataSendInfo> You're declaring a generic class with type parameters called SEND and CANDataSendInfo. You don't want this to be... more 3/22/2016 6:58:07 AM

people