Browsing 7239 questions and answers with Jon Skeet

get startday of month and endday of month using calendar class in Java

Given a year and a month; I want to get two Date Objects. one for startDate of the month and one for the end Date of the month. I have it implemented here and it works. but this...
Jon Skeet
people
quotationmark

You can make this code considerably simpler by making some assumptions: The first day of the month is always day 1 The minimum hour will always be 0 ... etc You can then find the last millisecond of the month by adding one month and... more 2/4/2014 9:03:50 PM

people

Implicit conversion issue with XmlElement ad XmlNodeList

I have a Xml document that I want to convert into a XnlNodeList using a linq query. Now, neither Xml nor Linq are something know well. The error I'm getting is Cannot implicitly...
Jon Skeet
people
quotationmark

You don't generally create XmlNodeList instances yourself. Do you really need one though? If you just need to iterate over the nodes, just assign it to an IEnumerable<XmlElement>: IEnumerable<XmlElement> abTestDocx =... more 2/4/2014 7:56:38 PM

people

How can I generate special characters in c#?

In Notepad, when I type alt+216 it outputs a character that is not available on my keyboard keys. I want to know how I can use this "alt+219" character in C# to generate a string...
Jon Skeet
people
quotationmark

Yes, you can represent all Unicode characters in C#, including in string literals. There isn't so much a list of "special" characters as a whole range of charts to look at. Find the character you're interested in is U+256A, as can be seen... more 2/4/2014 7:49:09 PM

people

Convert string variable to WaitCallback in ThreadPool.QueueUserWorkItem

Is it possible to pass string variable as a WaitCallback parameter in ThreadPool.QueueUserWorkItem() string myFunction="Go"; ThreadPool.QueueUserWorkItem(MyFunction); public...
Jon Skeet
people
quotationmark

You'll need to use reflection. For example: WaitCallback callback = (WaitCallback) Delegate.CreateDelegate( typeof(WaitCallback), this, myFunction); ThreadPool.QueueUserWorkItem(callback); To use a method in a different class,... more 2/4/2014 3:56:53 PM

people

IOrderedQueryable Skip and Take

I have the following abstract class which all of my Repositories inherit from: abstract class RepositoryBase<T> { void Add(); void Delete(); void...
Jon Skeet
people
quotationmark

It sounds like you should might want to make Paginate still take an IOrderedQueryable<T> to validate at compile-time that you've started with something that's ordered - but you don't then need to assign back to the same variable. For... more 2/4/2014 11:59:46 AM

people

C# Function parameter implementing abstract class and multiple interfaces

Consider the following structure in C#: interface I1 interface I2 abstract class A - class A1 : A - class A11 : A1, I1 - class A12 : A1, I2 - class A2 : A - class A21 :...
Jon Skeet
people
quotationmark

How can I define that parameter? You can't, basically. Not in a constructor. The closest you could come to would be to create a static generic method returning a B: public static B CreateInstance<T>(T item) where T : A,... more 2/4/2014 9:59:04 AM

people

Making a thread wait two seconds before continuing in C# WPF

I'm having trouble making a thread wait for two seconds without blocking the GUI. The most simple wait method I know is Thread.Sleep(2000);. If you can use some examples of timers...
Jon Skeet
people
quotationmark

If you're using C# 5, the simplest approach is to make the method async: private async void RunProgramClick(object sender, RoutedEventArgs e) { // Reverse the logic to reduce nesting and use "early out" if (comboBox1.Text !=... more 2/4/2014 8:50:46 AM

people

Gson serialize issue with backslashes java

Gson gson = new GsonBuilder().disableHtmlEscaping().create(); String path = "/folder1/folder2".replaceAll("/","\\\\/");//for get \/folder1\/folder2 String result =...
Jon Skeet
people
quotationmark

Your path contains backslashes, and those are being escaped by toJson(). When you deserialize at the other end, you'll end up with a string of \/folder1\/folder2 via normal JSON unescaping. I don't see this as an issue: the aim of... more 2/4/2014 8:38:39 AM

people

XElement and it's attributes

I've been looking for clarification between XName , XNamespace & XElement.Name.LocalName , from msdn.microsoft.com the example states that XNamespace ns =...
Jon Skeet
people
quotationmark

An XElement has a name, represented as an XName. That XName may or may not have a namespace associated with it. If it doesn't, the XName.Namespace property will return XNamespace.None. An XName is a fully-qualified name, basically -... more 2/3/2014 2:17:02 PM

people

Stream's capacity vs length

When I write some stream into a new memory stream, the length and capacity of the memory stream are both set to 0 at first, and grow along with the write process. but at some...
Jon Skeet
people
quotationmark

Shouldn't they be the same? No - or at least, not necessarily. This is basically the same as a List<T>'s capacity vs its count (or StringBuilder for that matter). The idea is that in order to minimize the number of times you... more 2/3/2014 1:56:05 PM

people