Browsing 7239 questions and answers with Jon Skeet

How to access a certain group of bytes in a MemoryStream?

I have a MemoryStream that reads some data during a do...while loop, and I need to check the last 5 bytes that have been read. How can I access the last 5 bytes read in a...
Jon Skeet
people
quotationmark

Just set the position to 5 bytes behind, and reread those bytes: byte[] GetLast5BytesRead(MemoryStream stream) { // TODO: Validation that stream.Position is at least 5 byte[] ret = new byte[5]; stream.Position -= 5; //... more 10/28/2013 5:27:33 PM

people

What's the name of this construction?

I'm reading a code that I didn't write. I stumbled upon the following statement: context.checking(new org.jmock.Expectations() { { ...
Jon Skeet
people
quotationmark

It's an anonymous class, with an instance initializer block in it. So to separate the two out: // This is an anonymous class Expectations expectations = new Expectations() { // Class body here }; class Foo { // This is an... more 10/28/2013 5:21:35 PM

people

SendKeys GUI Bug

I've made this program in C#: namespace Spammer { public partial class Form1 : Form { int delay, y = 1; public Form1() { ...
Jon Skeet
people
quotationmark

The problem is that you're using SendWait. That will wait for the target application to respond - and while that's happening, your application won't be able to respond to user input. If you use Send instead of SendWait, your UI thread... more 10/28/2013 3:54:26 PM

people

Visual Studio 2012 does not show folder has been created

I use Microsoft Visual Studio 2012. I first opened my ASP.NET project, then I created some folder as Pages, Views, Sources. But the second I open the project, Visual Studio...
Jon Skeet
people
quotationmark

Yes, this is because Visual Studio needs all its resources explicitly listed in its project files. When you add a folder in VS, it creates it on disk and changes the project file - whereas if you've added it in Explorer, the project file... more 10/28/2013 3:47:07 PM

people

Dates Not Matching

I have a TreeMap of <DDate, Integer>. DDate just contains month and year (month is 0 indexed, like in Java, JAN = 0); My compare is not returning the right...
Jon Skeet
people
quotationmark

You're setting the year, month and day - but that doesn't change the time of day. The internal clock must have ticked between the two calls to Calendar.getInstance, so they have different "milliseconds since the Unix epoch"... more 10/28/2013 2:40:39 PM

people

Why is the parameter is not updated?

I have a class that uses another class. The first class have this method: public void myMethod() { //Parameters are an enumeration. // Really is a exchange variable...
Jon Skeet
people
quotationmark

However, when in the clickButton I change the value of the _myParameters, is not changed in the object that was passed as parameter in the constructor of MyClass2. No, it wouldn't be. The value was passed in by value - the two... more 10/28/2013 12:56:23 PM

people

What is wrong with my Enumeration?

I am following the book and there is an example of enumeration. So I am doing this: enum Color { GREEN("GREEN"), YELLOW("YELLOW"), RED("RED"); String name; ...
Jon Skeet
people
quotationmark

Look carefully. Compare this: class TrafficLight extends enum<Color> with this class Suit extends Enum<Suit> Java is case-sensitive. Enum<Color> and enum<Color> are very different. (The latter is simply... more 10/28/2013 11:35:33 AM

people

C#/XML Reading XML File doesnt work

I want to read an XML-File and save the InnerText-Strings but it crashes with a SystemNullReference error. I think the way I read it is wrong but I'm not...
Jon Skeet
people
quotationmark

You're currently trying to get the Text node within the Text element, etc - but there isn't one. I suspect you want something like: case "Text": colorText = (Color) ColorConverter.ConvertFromString(node.InnerText); Alternatively,... more 10/28/2013 11:29:10 AM

people

Parameter constraints call method to check type in constraint?

I have a method with a generic parameter: internal void DoSomething<T>(T workWithThis) { } I now want to constrain this method to only accept parameters which inherit one...
Jon Skeet
people
quotationmark

Why is the compiler preventing me from doing that, based on my understanding there is no reason for it not to work The compiler is preventing you from doing it because you're trying to do something which isn't supported by C# as a... more 10/28/2013 10:23:15 AM

people

Why does the SendKeys Method delete the sign '+'?

So I should send a barcode, which include the sign +. The problem is that this sign don't appear on the application and delete the next number with. I should send this for...
Jon Skeet
people
quotationmark

From the documentation: The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). So you should send... more 10/28/2013 6:58:57 AM

people