Browsing 7239 questions and answers with Jon Skeet

Unable to modify IList object's members

I have created an IList variable as below: IList<vertex> matrix = new List<vertex> (); Here, vertex is a structure I defined with one of the members being visited...
Jon Skeet
people
quotationmark

When you fetch the vertex using the IList<T> indexer, that will return a copy of the value. Changing that copy wouldn't change the list - so the compiler stops you from writing incorrect code. Options: Make vertex a class instead... more 10/16/2013 3:54:56 PM

people

How do extension methods work in C#?

I'm not entirely sure as to how to figure out if a method is an extension method or not. I read the following guidelines: The method has to be in a static class (for example...
Jon Skeet
people
quotationmark

I don't understand is how we know which class the method is extending. Is it the class that has this preceding it? Yes. It's always the first parameter of the method. You can't decorate any other parameter with this. (And it's the... more 10/16/2013 3:21:36 PM

people

Static Methods ok to use when using parameters?

I understand that Static members can cause concurrency issues in ASP.Net or any other .net based system where multiple users will access and use the same threads. My question is...
Jon Skeet
people
quotationmark

I understand that Static members can cause concurrency issues in ASP.Net or any other .net based system where multiple users will access and use the same threads. Well only if it modifies shared state, or performs some sort of... more 10/16/2013 8:27:39 AM

people

LINQ to SQL query resulting in StackOverflowException

The LINQ to SQL query in the function below causes a StackOverflowException during run-time. What do I need to do to resolve this? I don't think it's an infinite loop problem - I...
Jon Skeet
people
quotationmark

I'm surprised that the current code is causing a stack overflow, but even if it weren't it couldn't work. Currently you're calling your local method from within your query: that's not going to work, as it can't be converted into... more 10/16/2013 7:19:54 AM

people

Writing a Map with single key and multiple values to Excel sheet

I have a Map with single key and multiple values.I'm trying to write those data in an excel sheet. Map<String, Object[]> data=new TreeMap<String, Object[]>(); In...
Jon Skeet
people
quotationmark

You wouldn't add the key inside the inner loop - it's not part of the data you're looping over. You need to add it before the loop: row.createCell(0).setCellValue(key); // Key is in column 0 int cellNum = 1; // Values now start at column... more 10/16/2013 6:02:17 AM

people

Java convert from String array to short array?

hello I have a commaseparated list of string and put into an array. I ultimately need them as a list of shorts, but the only way I know how to do that is get them as an array of...
Jon Skeet
people
quotationmark

Well presumably you just need to parse each element. But why not just add them to an ArrayList<Short>? List<Short> shortList = new ArrayList<Short>(stringArray.length); for (int i = 0; i < stringArray.length; i++) { ... more 10/15/2013 10:31:12 PM

people

C# & VS error: "make sure that the maximum index on a list is less than the list size"

I faced the error mentioned in the title when doing my homework, and simply can't find a way to remove it. Here is the method that I have this problem with: public static double...
Jon Skeet
people
quotationmark

Yes, this is the problem: for (int i = 0; i < luvut.Length; i++) { if (luvut[i] - ka < luvut[i + 1] - ka) When i is luvut.Length - 1, then i + 1 will be luvut.Length - and therefore an invalid index. (For an array of length x,... more 10/15/2013 9:21:05 PM

people

Why is my loop seeming to start at an index of 1?

public static void main(String args[]) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String[] label = new String[n]; int[] data = new int[n]; ...
Jon Skeet
people
quotationmark

The problem is that nextInt doesn't consume the line - just the integer. So you're actually getting labels of "", "one", "two" and "three" - and then it's trying to read the "four" as the first data element (with nextInt). If you type... more 10/15/2013 7:44:23 PM

people

Invalid expression term string in a method that accepts type as an argument

I am about to go crazy. I can't figure out why this won't work. Wrapper.DecompressAndDeserialize(string, ms); Here is the overload for the method: public static Object...
Jon Skeet
people
quotationmark

string is just the name of the type. You want an expression of type Type - in other words, a reference to an instance of Type for the relevant type. The simplest way to get that is with the typeof... more 10/15/2013 7:33:05 PM

people

Unable to instantiate activity componentinfo RunTimeException

Update below: I have this maps activity started when I click a button. I receive the below in the logcat. I have the activity added to the manifest. I have the setContentView...
Jon Skeet
people
quotationmark

Well I can work out the problem - but not a pleasant solution. Your activity indirectly subclasses ContextWrapper, which overrides getPackageName. The Geocoder creates a GeocoderParams with the given context (this in your case) and that... more 10/15/2013 6:00:17 PM

people