Browsing 7239 questions and answers with Jon Skeet

Avoid IndexOutOfRangeException by looping back to start of array

I have a array [4,4] that I am looping through and printing values. trainingpatterns.array = new int[4, 4]; for (int i = 0; i < 4; i++) { var...
Jon Skeet
people
quotationmark

I suspect you just want to use the % operator: int length0 = inputArray.GetUpperBound(0); int length1 = inputArray.GetUpperBound(1); ... var value = inputArray[x % length0, y % length1]; Note that this will not wrap negative numbers,... more 3/21/2014 1:20:05 PM

people

does Array.sort (or any collections sort method) depends on size of an individual items in C#?

As we all know the sort method the array works upon. The speed is affected by the number of items stored in an array. However would the speed be affected by the size of the...
Jon Skeet
people
quotationmark

Would the speed of sorting differ with 100 string items which are all 30 string characters? Potentially, yes. Potentially, no. It depends. If you have a bunch of strings which only differ at character 30, that will take longer to sort... more 3/21/2014 1:15:08 PM

people

Json with a strange name field cannot be parsed

I have this JSON container that has a strange field called "48x48" for a photoUrl. using Newtonsoft.Json; (...) dynamic issuesJson =...
Jon Skeet
people
quotationmark

For some reason Visual Studio doesn't accept the access to this runtime field of this dynamic object. Well what you've provided is simply not valid C#. An identifier can't start with a digit. That's still enforced even when you're... more 3/21/2014 1:12:04 PM

people

Why do I get an ArrayStoreException in Java?

My question is, why do I get an Exception in thread "main" java.lang.ArrayStoreException : at java.lang.System.arraycopy (native method) at java.util.ArrayList.toArray...
Jon Skeet
people
quotationmark

Basically you've got a List<Integer> and you're trying to store the contents of it in a String[]. You can't do that. If you want to convert each Integer into a String, you'll need to do that explicitly. For example: String[]... more 3/21/2014 12:59:10 PM

people

How do i create name of List dynamically?

I am trying to create = { "Data1":{ "DataListOne": [0, 1], "DataListTwo": [1, 0, 0, 0] }, "Data2":{ "DataListOne": [1, 0], "DataListTwo": [0, 0,...
Jon Skeet
people
quotationmark

I'd use Json.NET for this - it lets you build up the JSON dynamically: using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json.Linq; class Program { static void Main(string[] args) { var... more 3/21/2014 7:17:25 AM

people

How to invert parentheses?

I want to convert this () into this ) ( Like for example (1+2) to ) 1+2( i have tried this char[] cArray = text.ToCharArray(); for (int i = 0; i < text.Length; i++) ...
Jon Skeet
people
quotationmark

The problem is that after you've changed ( to ), the second if statement will immediately be true, so the character is flipped back again. The reverse isn't true though - if you start off with ) that will be flipped by the second... more 3/20/2014 8:55:44 PM

people

Java 8 Lambdas don't work, everything else from Java 8 works though

I found out that Java 8 is officially released now. It seems that I need Eclipse Luna 4.4 for it to work. So I downloaded Luna and installed it. I also imported all my projects...
Jon Skeet
people
quotationmark

Firstly, you don't need to use Luna - there's a feature patch for Kepler which works fine. Secondly, the "source compatibility" part of the Java Compiler dialog has to be 1.8. Otherwise even though you're allowed to use the library... more 3/20/2014 8:17:17 PM

people

Create new URI from Base URI and Relative Path slash makes a difference?

Why does a slash make difference when using new URI(baseUri, relativePath)? This constructor creates a Uri instance by combining the baseUri and the relativeUri .. And, how...
Jon Skeet
people
quotationmark

Why does a slash make difference when using new URI(baseUri, relativePath)? Well, that's what happens on the web normally. For example, suppose I'm looking at http://foo.com/some/file1.html and there's a link to file2.html - that... more 3/20/2014 7:59:48 PM

people

Console App, trying to move all files from "FolderX" to "FolderX":What am I doing wrong?

namespace FileMove2 { class Program { static void Main(string[] args) { Console.Write("Which folder would you like to move files from?"); ...
Jon Skeet
people
quotationmark

The problem is that File.Move takes two filenames, whereas you're providing a filename and a directory. You can fix your code by creating the appropriate target filename: string targetFile = Path.Combine(targetPath,... more 3/20/2014 7:54:20 PM

people

Why does the this generic function not call the overriden function

If I have a base class class Foo : IClonable { public object virtual Clone(){ return new Foo(); } } and a child class incorrectly overriding clone with new instead of...
Jon Skeet
people
quotationmark

Is it that the type T is erased after the constraints are met and then it just behaves using the base class? It depends on what you mean by "the type T is erased". It's not erased in the same way that it is in Java - the type argument... more 3/20/2014 3:35:09 PM

people