Browsing 7239 questions and answers with Jon Skeet

Illegal start of expression string

I am trying to make a program that reverses the text lines in a file. I am still learning java and I am new to this. My program was erroring because I made a variable inside a...
Jon Skeet
people
quotationmark

Problems: You're declaring lines with the public modifier, which is only for instance/static variables, not local variables. You're never initializing lines You're trying to use lines outside its scope (which is currently the while... more 10/6/2013 3:34:25 PM

people

InvalidCastException Dictionary<string, string> using Exception.Data

I have a Client/Server package that I am playing with, I am trying to use Exception.Data to pass custom information into a separate class (ExceptionError) to pass into a...
Jon Skeet
people
quotationmark

Basically, the value of Exception.Data isn't a Dictionary<string, string> - so when you cast it to Dictionary<string, string>, you get this exception. The property itself is only declared to be of type IDictionary. You... more 10/6/2013 11:30:21 AM

people

wrong Reading with BufferedReader

I have problem with reading data from file. In each line (except first) first char is lost! Maybe i have troubles with coding, but i try to set UTF-8, UniCode, ANSI, and result...
Jon Skeet
people
quotationmark

The problem is with the end of your do loop: do { input = br.readLine(); if (input.endsWith("\n")) { input = input.substring(0, input.indexOf("\n")); } System.out.println(input); } while (br.read() != -1); You're... more 10/6/2013 8:32:58 AM

people

Correctly receiving data using StreamSocket hangs

I am using a StreamSocketListener to receive data on a Windows Phone 8 (acting as server) sent by a HTTP POST client. I can receive the data but when all data is read the...
Jon Skeet
people
quotationmark

Presumably the client is using HTTP 1.1 with connection keep-alive - so it's not closing the stream. You're waiting for the client to send more data, but the client has no intention of sending any more data because it's "done" for that... more 10/6/2013 8:20:28 AM

people

In .NET, can a base class somehow ensure derived classes define shared members?

When I inherit from a base class, Visual Studio (v2008 here) informs me about all MustInherit members that need to be created in the derived class, which is very handy. However,...
Jon Skeet
people
quotationmark

No, there's no way of doing this - and it sounds like a design smell, to be honest. Half the point of having MustInherit members is that you can then access them from the code in the base class. That wouldn't be appropriate for Shared... more 10/6/2013 8:07:56 AM

people

calculating average of difference between numbers using linq

I have a column which has double values. I have to calculate the average of the difference between each values upon all the values in the column. for example: for 1, 2, 3.5 the...
Jon Skeet
people
quotationmark

You can use Zip and Skip together to create the "difference between adjacent numbers" part, and then the normal average: var differenceAverage = input.Zip(input.Skip(1), (x, y) => y - x).Average(); This relies upon the ability to... more 10/6/2013 7:04:12 AM

people

Creating a List<T>, issues with formatting

I'm getting all sorts of compile errors from the code below. I'm not quite sure how to Add items to a List when I have a List setups as shown below. I wan't to basically maintain...
Jon Skeet
people
quotationmark

Aside from anything else, this could be the problem: _stocks.Add(new StockItem(StockEntry("ABC", PeriodType.Minute, 5))); (and the similar lines). StockItem is a generic class, so you need to specify the type... more 10/5/2013 7:23:44 PM

people

Passing List between C# Forms

I am trying to learn passing a list between two C# forms using constructors as shown below. On the first form I did: List<Cat> myCatList; //list populating...
Jon Skeet
people
quotationmark

The List part is a complete red herring here. You'd get exactly the same problem if your constructor had a Cat parameter instead of a List<Cat> parameter. Your Cat type is probably internal, because you haven't declared it as... more 10/5/2013 7:15:13 PM

people

Trying to add with method, believe something is not instantiating

When I type in the textbox, I am wanting it to add the numbers, instead if I type (for example) 12, and click deposit again, it only shows 12. I think this is because it seems to...
Jon Skeet
people
quotationmark

You're creating a new instance of BankAccount each time the button is clicked - so accountBalance will be 0.0 (the default value for a field of type double). How did you expect it to "know" about the previous balance? It's entirely... more 10/5/2013 7:09:23 PM

people

Am I not returning a string?

I'm writing a method to find the upper case letters in a given string. I have this public static String FindUpperCase (String x){ for (int i = x.length(); i>=0; i--){ ...
Jon Skeet
people
quotationmark

No, you're not always returning a string. What if the input is entirely lower case? Basically, you need a return statement (or throw an exception) after the for loop, to handle the situation where you get to the end of it. Even in cases... more 10/5/2013 6:39:43 PM

people