Browsing 7239 questions and answers with Jon Skeet

text file: Reading line by line C#

So, let's say i have a text file with 20 lines, with on each line different text. i want to be able to have a string that has the first line in it, but when i do NextLine(); i...
Jon Skeet
people
quotationmark

Well, if you really don't mind re-opening the file each time, you can use: CurrentLine = File.ReadLines("c:\\test.txt").Skip(LastLineNumber).First(); LastLineNumber++; However, I'd advise you to just read the whole thing in one go using... more 2/18/2014 5:51:04 PM

people

Find Quarter based on Weeks in Java

I am trying to get the quarter in the year using calender class in Java. I am getting current date as below and use WEEK_OF_YEAR variable to get the week as below but below output...
Jon Skeet
people
quotationmark

Calendar.WEEK_OF_YEAR is a constant. You wanted cal.get(Calendar.WEEK_OF_YEAR). However, you should note that "week of year" is not as simple as you might expect, as a concept. For example, it can be 53 on January 1st, which belongs to... more 2/18/2014 5:46:24 PM

people

Converting VB sub procedure to C#

In VB, I have classes that look like: Public Class Example Public test1 As New List(of String) Public test2 As New List(of String) Public Sub Init() //code...
Jon Skeet
people
quotationmark

My understanding is that this Sub Init() procedure works like a main method in C#, in that everytime the Example class is used, this method is initialized automatically. No, that's not a correct understanding of either the Init method... more 2/18/2014 5:36:11 PM

people

Why java Path.Separator in JSON file format is switched to \?

I want to put a picture path in a jsonObject and pass it to javascript, in java i do JSONObject assets = new...
Jon Skeet
people
quotationmark

By the time the data has been read within Javascript, it will have the appropriate name. This is just an escape sequence, which doesn't change the value of the data. For example, in a Javascript console: var x = "foo\/bar"; var y =... more 2/18/2014 5:34:18 PM

people

Use of Unassigned Local variable when adding item in listview

I'm trying to compare if item is already existing in listview. It says : Use of unassigned local variable 'alreadyInList' bool alreadyInList; foreach (var itm in...
Jon Skeet
people
quotationmark

Others have said how you can avoid the definite assignment problem. Local variables always need to be definitely assigned before they are first read. However, I'd suggest using LINQ to make the code simpler anyway: bool alreadyInList =... more 2/18/2014 5:31:45 PM

people

Thread does not start in a Swing application

I am working on a relatively simple DB manager, that takes in a number of files, parses and catalogs the information in a particular fashion. I also wrote a simple GUI in Swing...
Jon Skeet
people
quotationmark

You're calling run() on the newly created Thread object in ParserType1.init(). That doesn't start a new thread - it just execute's the thread's run() method in the existing thread. You should be calling start() instead. Fundamentally I... more 2/18/2014 3:28:17 PM

people

What is the limit of the Value Type BigInteger in C#?

As described in MSDN BigInteger is : An immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. As I can see...
Jon Skeet
people
quotationmark

As I can see BigInteger is a ValueType, as much as I know, a ValueType must have a maximum size of 16 bytes. No, that's not true. It's a conventional limit, but it's entirely feasible for a value type to take more than that. For... more 2/18/2014 2:29:17 PM

people

What will happen to variable Declared in Interface ? if the implemented class has the same variable?

The code is below. public interface DesignPatternInterface { int CUSTOMERAGE = 45; } public class ImplementInterface extends AbstaractDemo implements DesignPatternInterface...
Jon Skeet
people
quotationmark

My question is interface variable is static final Yes. From section 9.3 of the JLS: Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of... more 2/18/2014 2:20:11 PM

people

DateTime to Datetime2

I have started to use entity framework and after doing research i have found that Entity Framework only accepts the DateTime format DateTime2. What is the best way to convert a...
Jon Skeet
people
quotationmark

Don't perform any string conversions. Just use DateTime value = dtCastFrom.Value; Let the Entity Framework itself take care of getting the data to the database. You don't want a string representation, and there's no reason to go via a... more 2/18/2014 2:18:13 PM

people

Generated code differs when compiling solution in VS2010 or via MsBuild command line

I have the following C# code: foreach (var x in m_collection) { m_actionCollection.Add(() => { x.DoSomething(); }); } If I compile the solution in VS2010...
Jon Skeet
people
quotationmark

I suspect you're seeing the difference between the C# 5 compiler (invoked via msbuild) and the C# 4 compiler (in VS2010). I'm somewhat surprised that msbuild is using the C# 5 compiler, but it appears to be... The rules for how a foreach... more 2/18/2014 9:31:59 AM

people