Browsing 7239 questions and answers with Jon Skeet

Having trouble populating listbox from xml elements

The XML is as followed: <?xml version="1.0" encoding="utf-8"?> <Folder_Settings> <Documents>Checked</Documents> <Pictures>Not...
Jon Skeet
people
quotationmark

The reason your code isn't working is because your loop is: for (var i = 0; i <= folderList.Count; i++) ... where folderList is the list of Folder_Settings elements. There's only one of those, so you're iterating twice. It's a good... more 5/20/2015 5:32:30 PM

people

How to Emit code to assign value/reference to static field of class by calling it's constructor?

(My code is somewhat a mess of C# and VB.NET) I am trying to Emit class that looks as following: public class SWTTFields { private string fieldName; private int...
Jon Skeet
people
quotationmark

I haven't used TypeBuilder myself so this is more of a hint than full code, but basically I believe you want TypeBuilder.DefineTypeInitializer, and perform the assignments in there. In other words, think of the class as looking like this,... more 5/20/2015 4:43:49 PM

people

select distinct xelement based on attribute

<field name="value" value="A" /> <field name="value" value="B" /> <field name="text" value="C" /> <field name="text" value="D" /> <field...
Jon Skeet
people
quotationmark

It sounds like you need DistinctBy from MoreLINQ: var distinct = elements.DistinctBy(x => x.Attribute("name").Value); more 5/20/2015 1:04:49 PM

people

Why do we have String class, if StringBuilder or StringBuffer can do what a String does?

I've always wondered why does JAVA and C# has String (immutable & threadsafe) class, if they have StringBuilder (mutable & not threadsafe) or StringBuffer (mutable &...
Jon Skeet
people
quotationmark

I mean, why should I use String class, if I've option of using StringBuilder/StringBuffer? Precisely because it's immutable. Immutability has a whole host of benefits, primarily that it makes it much easier to reason about your code... more 5/20/2015 12:49:12 PM

people

Creating an object variable out of its meta object

I have a method (in a class which represent a set of objects) that receive as a parameter a Class object, and I need to find all the objects in the set that have this Class object...
Jon Skeet
people
quotationmark

Well, as you've shown you're going to return it as Object[] anyway, so you won't get a compile-time benefit here, but you can create an array of the right type easily enough: Object[] array = (Object[]) Array.newInstance(meta,... more 5/20/2015 12:40:38 PM

people

Next 2 hours using Calendar object/Java Android

I want to capture the number of steps the user is doing for the next 2 hours. This is what I am putting. Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR,...
Jon Skeet
people
quotationmark

Look at what you're doing: long endTime = calendar.getTimeInMillis(); calendar.add(Calendar.HOUR_OF_DAY,2); long startTime = calendar.getTimeInMillis(); So your start time is two hours after your end time. That's not going to be valid.... more 5/20/2015 12:33:36 PM

people

DateTime conversion in Linq c#

I'm trying to write a query who select all data who was created today. Here is my request : public List<Projet> GetEnvoiMailBienvenueProjet(Site site) { ...
Jon Skeet
people
quotationmark

I would recommend that you get rid of the string conversion entirely: DateTime today = DateTime.Today; var res = _context.Projet.Where( a => ... && a.CreationDate == today); Or possibly (if a.CreationDate... more 5/20/2015 9:03:23 AM

people

Date Issue when change Timezone to London

I have the code below: package com.company.customer; import java.util.*; import java.text.*; import java.io.*; public class DateSample { private TimeZone GMT_TIMEZONE =...
Jon Skeet
people
quotationmark

You haven't set the time zone for formatter, so that's whatever the system default time zone is. So, you're parsing "2015-07-15" using the system default time zone. If that's London, you're parsed date is 2015-07-15T00:00:00+01 which is... more 5/19/2015 7:56:04 PM

people

Strange behaviour of singleton

I assign the reference of singleton object to null. But still it is calling method of the Singleton class. Here is my code class Singleton { private static Singleton...
Jon Skeet
people
quotationmark

You're calling demoMethod, which is a static method - so your code here: tmp.demoMethod(); is actually being compiled to: Singleton.demoMethod(); That clearly doesn't depend on the value of tmp. This has absolutely nothing to do... more 5/19/2015 6:51:31 PM

people

Escaping the "|" sign in java

I need to split a spring delimited by "|". When I use String.split("|") it doesn't give me the correct result. String[] arr = "1234|5678".split("|"); ...
Jon Skeet
people
quotationmark

You need to understand that there are two levels of escaping here: String literal escaping Regular expression escaping You want a regular expression with the pattern \| - but in order to write that as a string literal, you need to... more 5/19/2015 6:48:44 PM

people