Browsing 7239 questions and answers with Jon Skeet

C# .NET Why Stream.Seek is required when unzipping stream

I'm working on a project where I need the ability to unzip streams and byte arrays as well as zip them. I was running some unit tests that create the Zip from a stream and then...
Jon Skeet
people
quotationmark

When you return output from ZipObject, that stream is at the end - you've just written the data. You need to "rewind" it so that the data can then be read. Imagine you had a video cassette, and had just recorded a program - you'd need to... more 9/26/2013 12:29:20 PM

people

I am getting error when trying to connect to MySql using JSP page

I am unable to connect to MySql using JSP page. This is my connection query - <% String driver = "com.mysql.jdbc.Driver"; Class.forName("Driver").newInstance(); Connection...
Jon Skeet
people
quotationmark

This is incorrect: Class.forName("Driver").newInstance(); That's trying to find a class called Driver in the default package. You potentially want: Class.forName(driver).newInstance(); ... but even that shouldn't be required: Just... more 9/26/2013 12:14:25 PM

people

Thread notification don't work

I can't find reason why ThreadA gets notification from ThreadB only when ThreadB completely finishes it's job. If I comment notify() ThreadA gets notification anyway. Does...
Jon Skeet
people
quotationmark

Firstly, please don't use Thread objects like this. Thread uses wait and notify itself, so you can easily end up with confusing signals. The reason you're not seeing "waiting done" until the end is that although ThreadB.run calls... more 9/26/2013 10:41:00 AM

people

Check if Action is async lambda

Since I can define an Action as Action a = async () => { }; Can I somehow determine (at run time) whether the action a is async or not?
Jon Skeet
people
quotationmark

No - at least not sensibly. async is just a source code annotation to tell the C# compiler that you really want an asynchronous function/anonymous function. You could fetch the MethodInfo for the delegate and check whether it has an... more 9/26/2013 9:16:33 AM

people

Difference between syntaxes

I am working on developing custom pager control to my grid view. I am using the following syntax to get no of pages: dblpagecount = (doble)(totrecords /...
Jon Skeet
people
quotationmark

I'm assuming that both totrecords and grdPages.PageSize are of type int. Therefore, regardless of the type of dblpagecount, you'll end up with the division being performed in integer arithmetic, which truncates towards 0. However, I... more 9/26/2013 8:16:17 AM

people

What to change in list sorting to sort it properly

I can't sort my list entirely. It's int based sorting and I used CompareTo() form IComparable, custom Comparer delegate, and anonymous delegate. None of this work for me. here is...
Jon Skeet
people
quotationmark

You're sorting it in ascending order, rather than descending... but your test requires that the highest scoring player is first. This should work: // Use the overload taking a Comparer<Player> delegate for... more 9/26/2013 7:45:44 AM

people

xPath.evaluate only returns a single node

I have the following XML structure: ... ... <CON> <LANGUAGES> <LANGUAGE>Deutsch</LANGUAGE> <LANGUAGE>English</LANGUAGE> ...
Jon Skeet
people
quotationmark

How can I get the two languages? By asking for the LANGUAGE elements instead of LANGUAGES - after all, there is only one LANGUAGES element. So something like this: NodeList nl =... more 9/26/2013 7:43:35 AM

people

Enum flags over 2^32

I am using Enum flags in my application. The Enum can have around 50+ values, so values go up to 2^50. I was just wondering, can I use Math.Pow(2, variable) to calculate...
Jon Skeet
people
quotationmark

When I try to do that I get a constant value compile-time error. You'd actually be okay if you used the L suffix to force it to be a long literal - but it's still not ideal to have to specify them all manually. (It's not "obviously... more 9/26/2013 7:21:34 AM

people

How events are more robust than delegates

Consider the following example. The Stock class fires its PriceChanged event every time the Price of the Stock changes: public delegate void PriceChangedHandler (decimal...
Jon Skeet
people
quotationmark

My question is in what way the event keyword makes the stock more robust? It's all a matter of what clients outside the class can do. If this were just a public field, then anyone could: Call all existing handlers... more 9/26/2013 6:46:59 AM

people

java unicode conversion on linux not working on max os x

I am writing a java application on Ubuntu Linux that reads in a text file and creates an xml file from the data. Some of the text contains curly apostrophes and quotes that I...
Jon Skeet
people
quotationmark

Chances are you'tr not reading the file correctly to start with. You haven't shown how you're reading the file, but my guess is that you're just using FileReader, or an InputStreamReader without specifying the encoding. In that case, the... more 9/25/2013 10:51:24 PM

people