Browsing 7239 questions and answers with Jon Skeet

C# Tasks not working as expected. Bizarre error

I've been toying with parallelism and I'm having some trouble understanding what's going on in my program. I'm trying to replicate some of the functionality of the XNA framework....
Jon Skeet
people
quotationmark

The problem is that your lambda expression is capturing i - not the value of i, but the variable itself. That means that by the time your task executes, the loop may well be on the next iteration (or even later). So some of your... more 12/31/2013 7:53:39 AM

people

Nested select group by linq statement

I have spent days (maybe weeks) trying to resolve this issue. I have two tables in which I am trying to organize my data into the following hierarchy. Here is an example of what...
Jon Skeet
people
quotationmark

This is the problem: select new wl{d.Key.cat_id} It's not clear what you actually intended to do here (the meaningless type names really don't help) but you might want something like: select new wl { CategoryId = d.Key.cat_id... more 12/30/2013 7:45:52 PM

people

package org.apache.commons does not exist

I'd love to use EnumeratedIntegerDistribution() from org.apache.commons.math3.distribution, to get discrete probabilities distribution int[] nums_to_generate = new int[]...
Jon Skeet
people
quotationmark

This is the problem: import org.apache.commons.math3; That's trying to import a package - you can't do that. You have to either use a wildcard import: import org.apache.commons.math3.*; or import a specific type: import... more 12/30/2013 5:55:20 PM

people

DateTime.Now and Culture/Timezone specific

Our application was designed to handle user from different Geographic location. We are unable to detect what is the current end user local time and time zone operate on it....
Jon Skeet
people
quotationmark

It sounds like you need to store a DateTimeOffset instead of a DateTime. You could just store the local DateTime to the user creating the value, but that means you can't perform any ordering operations etc. You can't just use... more 12/30/2013 4:55:40 PM

people

Weird behavior of File.pathseperator java

I am developing a program in Java that associates with a file, so I useFile.separator in order to manage it. The weird fact is that everywhere I call it, it returns the \ as it...
Jon Skeet
people
quotationmark

No, File.pathSeparator is ; on Windows. For example, you might have: PATH=c:\Utils;c:\SomethingElse File.pathSeparator is ; on Windows and : on Unix. You're thinking of File.separator which would be \ on Windows and / on Unix. Here's... more 12/30/2013 4:29:46 PM

people

How to Cast XmlCDataSection to XDocument

Does anyone know how to cast XmlCDataSection to XDocument in C#? This is what I have so far but its not working: XmlCDataSection xcData = xcDataInput as...
Jon Skeet
people
quotationmark

It's not clear why you're using Cast or Select at all. I suspect you just want: XDocument xdoc = XDocument.Parse(xcData.InnerText); Note that I'm using InnerText rather than OuterXml, as the outer XML of a CDATA node will never be a... more 12/30/2013 3:24:41 PM

people

The process cannot access the file because it is being used by another process error

here is my code: public static bool createFile(string dir) { dir="c:\\e.bat"; System.IO.File.Create(dir); if (System.IO.File.Exists(dir)) ...
Jon Skeet
people
quotationmark

You're calling File.Create at the start of the method - which is returning you a stream, which stays open. It's not clear why you're calling that at all, but I'd suggest just removing that line. You should also use a using statement, only... more 12/30/2013 1:07:32 PM

people

Difference between buffered reader and file reader and scanner class

Can anyone explain me the difference between the class BufferedReader, FileReader and Scanner? and which one to use when I want to read a text file?
Jon Skeet
people
quotationmark

Well: FileReader is just a Reader which reads a file, using the platform-default encoding (urgh) BufferedReader is a wrapper around another Reader, adding buffering and the ability to read a line at a time Scanner reads from a variety of... more 12/30/2013 11:09:49 AM

people

Completing work in constructor VS using an initializer

From what I have seen in other peoples code, there appears to be two ways common ways in creating an object and "readying" it to be used. Method 1: Ready the object in the...
Jon Skeet
people
quotationmark

One reason for using the constructor is that you can make the field final - immutability isn't an option if you the constructed object isn't fully initialized. Personally I prefer to write code so that by the time an object is available,... more 12/30/2013 10:54:18 AM

people

C# exception handling in sharepoint know for sure file is not found

This is my Code: try{ using (Microsoft.SharePoint.Client.ClientContext context = new Microsoft.SharePoint.Client.ClientContext(siteURL)) { ...
Jon Skeet
people
quotationmark

When you get a WebException, you can use the Response property to access the response from the web server (if there is one). You can then cast that to the appropriate subclass, and check the error code: catch (WebException e) { var... more 12/30/2013 10:14:09 AM

people