Browsing 7239 questions and answers with Jon Skeet

cannot convert from 'string' to 'System.Collections.Generic.IEnumerable<string>

This is my code: string path = @"c:\temp\mytext.txt"; string[] lines = System.IO.File.ReadAllLines(path); foreach (var line in lines) { var firstValue = line.Split(new...
Jon Skeet
people
quotationmark

File.WriteAllLines takes a sequence of strings - you've only got a single string. If you only want your file to contain that single string, just use File.WriteAllText: File.WriteAllText(@"C:\temp\WriteLines.txt", firstValue); However,... more 1/4/2014 2:26:05 PM

people

Equivalent of internal in java

What is equivalent of internal access modifier available in C# for method in Java? (I know default i.e. methods, variables without any scope are having package access but I am...
Jon Skeet
people
quotationmark

There's no equivalent of an assembly in Java, so there can't be an equivalent of an access modifier which makes a member available within an assembly. The closest you can get to internal is the default accessibility which is similar but... more 1/4/2014 1:23:27 PM

people

Does a C# indexer return a variable or value?

Mutable structs are error-prone; dictionary[0].Inflate(1,1) doesn't behave the same as array[0].Inflate(1,1) would when T is a Rectangle (since array[0] is a variable, whereas...
Jon Skeet
people
quotationmark

An indexer access expression is initially classified as an "indexer access". From section 7.6.6.2 of the C# 4 spec: The result of processing the indexer access is an expression classified as an indexer access And then from section... more 1/4/2014 10:56:01 AM

people

Combine two double jagged array in one jagged array in C#

I'm doing my project and I'm facing to a problem with combining two jagged arrays and create one. Below is a example: Jagged one : double[][] JaggedOne= { new double[] { -5,...
Jon Skeet
people
quotationmark

The fact that they're jagged arrays is actually irrelevant here - you've really just got two arrays which you want to concatenate. The fact that the element type of those arrays is itself an array type is irrelevant. The simplest approach... more 1/4/2014 10:18:37 AM

people

I have the error width cannot be resolved or is not a field (It's on the render.width at the end)

This is the error at the end(render.width) pixels[xPix+yPix*width] = Render.pixels [x + y * render.width]; } Here is the full code package...
Jon Skeet
people
quotationmark

That line of code is outside the method - so it's render that's not being found. Additionally, you have a spurious ; in your for loop declaration: for (int y = 0; y<render.height; y++); ^--- You... more 1/4/2014 10:03:22 AM

people

Java: make subclass be comparable only with the same subclass

I have an abstract Dice class and there are some concrete subclasses like SixFacesDice, TwentyFacesDice, etc... I want every Dice object to be comparable with an other but only if...
Jon Skeet
people
quotationmark

Assuming you want compile-time safety rather than just execution-time safety, you could use generics, like this: abstract class Dice<T extends Dice> implements Comparable<T> { int value; public int compareTo(T other)... more 1/4/2014 9:56:08 AM

people

java: local variable looper is accessed from within inner class; needs to be declared final, but then variable might not have been initialized

I'm using something a bit like the command pattern to create a class which implements a simple interface for a method I reuse frequently, but in different ways. I was able to get...
Jon Skeet
people
quotationmark

You've effectively got a cyclic dependency: your Looper needs to be initialized with the Commandable, and the Commandable needs to be initialized with the Looper. The compiler is absolutely right to complain - imagine if the Looper... more 1/4/2014 9:32:44 AM

people

Follow up to BigDecimal new or valueof

This question is a follow up to the question (BigDecimal - to use new or valueOf) and its accepted answer. To reiterate the question and answer for convenience: BigDecimal has...
Jon Skeet
people
quotationmark

Firstly, any time you convert from a double to BigDecimal you should take a step back and ask yourself whether you're really doing the right thing to start with. For example, if you've done this by parsing from a String to a double, then... more 1/3/2014 6:11:11 PM

people

Using parametrized thread

I'm trying to create some number of threads which would be equal to nOfplayers. I'm doing it like this: for (int i = 0; i < nOfPlayers; i++) { thr[i] = new Thread( ...
Jon Skeet
people
quotationmark

No, it's executing the right number of times - but you're capturing i, which is incrementing before the thread gets to use it. Create a copy of i in your loop: for (int i = 0; i < nOfPlayers; i++) { int player = i; thr[i] =... more 1/3/2014 10:11:49 AM

people

how to check given date exist in month or not?

I have a combo Box In which I made a collection of dates from 1 to 31 and also I have a checklist box in which I made a collection of month from Jan to Dec. Now I have to put...
Jon Skeet
people
quotationmark

You want the DateTime.DaysInMonth method: public bool IsDateValid(int year, int month, int day) { return day <= DateTime.DaysInMonth(year, month); } I'm assuming that the year and month values will always be sensible, and that... more 1/3/2014 9:36:00 AM

people