Browsing 7239 questions and answers with Jon Skeet

Split a list into sublist by a separator not by index in C#

I read this question: Split List into Sublists with LINQ but it not help me for the following problem. I have the following...
Jon Skeet
people
quotationmark

I'm not aware of an existing operator to do this in LINQ to Objects itself, more the MoreLINQ project has the Split method, so you can use: var sections = originalList.Split("-----"); That returns an... more 9/23/2014 4:19:51 PM

people

How to read xml from web response?

I am trying to read xml from web response and get selected nodes (i.e link) from it. This is what I have so far and its showing "System.Xml.XmlElement", as an output. WRequest...
Jon Skeet
people
quotationmark

The immediate problem (the reason you're seeing System.Xml.XmlElement) is that you're calling ToString on an XmlElement, which doesn't override that method. You probably want to use the InnerXml or OuterXml properties instead: XmlNode... more 9/23/2014 3:07:29 PM

people

Get/Set from C# to Java

I'm working on a project to translate a c# project to Java. I have the following Get/Set block in C# public Unit[] Units { get { Unit[] units_aux = new...
Jon Skeet
people
quotationmark

You'd basically have to convert it to a pair of methods: public Unit[] getUnits() { // Method body } public void setUnits(Unit[] value) { // Method body } Java doesn't have properties at a language level - the above is... more 9/23/2014 11:29:11 AM

people

How to convert DateTime to string in C# using Oracle date format

Goal Convert a DateTime to string using an Oracle datetime format[1] like "IY-IW". Description I have a situation where I'm provided a DateTime and an Oracle date format...
Jon Skeet
people
quotationmark

Is there a simple way to achieve the goal? Almost certainly not. Like using DateTime.ParseExact and somehow specifying that an Oracle date format is used? No - .NET doesn't know about the Oracle date/time format. Converting... more 9/23/2014 9:16:11 AM

people

How to handle/enforce single instance threading

I have a "worker" process that is running constantly on a dedicated server, sending emails, processing data extracts etc. I want to have all of these processes running...
Jon Skeet
people
quotationmark

This sounds like a perfect job for either an actors framework, or possibly TPL Dataflow. Fundamentally you've got one actor (or block) for each job, waiting for messages and processing them independently of the other actors. In either... more 9/22/2014 4:47:39 PM

people

Convert UTC to LocalDateTime in Joda?

DateTime dt = new DateTime("2014-09-15T21:20:14"); System.out.println(dt); System.out.println(dt.plusMillis(581042272).toDateTime().toLocalDateTime().toDateTime(DateTimeZone.forID("GMT"))); the time in dt is in UTC, I want to set the time in dt plus milliseconds to GMT? However, the time is still printed as UTC (1 hour behind GMT). How can I set it so it's one hour in front? 2014-09-15T21:20:14.000+01:00 2014-09-22T14:44:16.272Z I know the time is exactly one hour behind because I made this request at 15:44:16 GMT
Jon Skeet
people
quotationmark

Your DateTime is actually not in UTC - it's in the system default time zone. To fix it, you just need to tell it that the value you're passing in is in UTC: DateTime dt = new DateTime("2014-09-15T21:20:14",... more 9/22/2014 3:04:08 PM

people

doesn't it need to delete thread object?

i have a search thread in my project . the thread is created in 'Form1()' function: objSearchThread = new Thread(this.Thread_Func); when user clicks the 'search' button,...
Jon Skeet
people
quotationmark

No, you don't need to do anything. The thread will just finish when it has no more work to do. You might want to consider scheduling it to execute on the thread pool however, instead of creating a new thread each time. You could do that... more 9/22/2014 11:05:25 AM

people

Efficiency of DispatcherTimer versus Thread.Sleep

What is more efficient to use, DispatcherTimer or Thread.Sleep in C#? I could use DispatcherTimer: DispatcherTimer timer = new DispatcherTimer(); timer.Interval =...
Jon Skeet
people
quotationmark

If you need to operate in the dispatcher thread, then you really don't want to use Thread.Sleep - you'd end up blocking the dispatcher thread, so your user interface would be frozen. You could have a background thread sleeping for 20... more 9/22/2014 9:25:57 AM

people

Which class can not be a subclass in java and why?

I am not getting this question correctly: Which class can not be a subclass in java and why? a.) abstract class b.) parent class c.) final class d.) none of ...
Jon Skeet
people
quotationmark

Any of these can be a subclass. For example: public class Superclass { } public abstract class AbstractSubclass extends Superclass { } public class MiddleClass extends Superclass { } public class BottomClass extends MiddleClass... more 9/21/2014 3:38:22 PM

people

Error in testing

I am having problems with my test. It looks like it's simple. All you have to do is delete a space, but I keep getting an error for some reason. @Override public String...
Jon Skeet
people
quotationmark

The problem is just %2d - you've explicitly asked for the number of seconds to be converted into a minimum of two characters. Just make it %d and it should be fine. See the Formatter documentation for details. Note that at the moment, if... more 9/20/2014 3:19:28 PM

people