Browsing 7239 questions and answers with Jon Skeet

Array assignment output behaves differently for two code snippets

First code snippet prints 2 public static void main(String args[]) throws Exception { int[] a = { 1, 2, 3, 4 }; int[] b = { 2, 3, 1, 0 }; int val = (a = b)[3]; ...
Jon Skeet
people
quotationmark

The output is reasonable. Let's expand the two complicated lines into several separate statements. First snippet: // This... int val = (a = b)[3]; // Becomes... a = b; int val = a[3]; // 0 So printing a[val] will print a[0], which is... more 10/11/2014 7:35:37 AM

people

How do I return a not complete object?

My select statement does not return the entire Customer object, just the utrustningNr and beskrivning. How do i return it in a correct way without getting this error: Cannot...
Jon Skeet
people
quotationmark

The problem is that your select clause is creating a new anonymous type for each item, instead of a new utrustning. You may well want something like: var queryEquipment = from utrustning in globalDBConnString.context.utrustnings ... more 10/10/2014 8:11:18 PM

people

Removing enum flags

I'm a little bit puzzled by the removal of enum flags to be perfectly honest. Let me make an example, let's say we have an enum that looks like this [Flags] enum Letter { A...
Jon Skeet
people
quotationmark

Yes, the problem with the XOR operator is that unless you know that you've got all the rest of the flags, it will just flip them. So your XOR operation isn't "remove all but C" - it's "toggle the values of A and B". (So if the input was... more 10/10/2014 7:59:57 PM

people

Problems parsing XML in Java with XMLStreamReader

Here I have some code responsible for fetching the attribute value: currPost.Body = reader.getAttributeValue("", "Body"); so, Body is the very attribute my problem is based...
Jon Skeet
people
quotationmark

I suspect the problem is the 

 in your XML. That's U+000A, or "line feed" (twice). You can validate that this is the problem by taking the XML out of it entirely. See what this does: System.out.println("Line... more 10/10/2014 7:40:54 PM

people

How to convert a date having ordinal format 1st March 1994?

I want format a date given in the following format 1st March 1990. The date should be formatted to YYYY-MM-DD. I have the following code. It gives me an unparsable date. From this...
Jon Skeet
people
quotationmark

You have three problems. First, you're trying to parse the date using the format YYYY-MM-DD. That's not the format of your data, which is why parsing is failing. Second, you're expecting a Date object to retain information about a... more 10/10/2014 7:35:51 PM

people

Get minimum value in linq query

I'm using Entity Framework for my DB access. One of the entities is Products, and a Product can have many Terms. Here's the Term class: public partial class Term { public...
Jon Skeet
people
quotationmark

Does Product have a Terms property? If so, it's pretty easy: var minMinTerm = products.SelectMany(product => product.Terms) .Min(term => term.MinTerm); The SelectMany method "flattens" a sequence - so you... more 10/10/2014 2:45:53 PM

people

validating decimal numbers in culture

can anyone please explain why, in 'en-GB' culture formatting, the decimal.Parse() function would return 15 for 1,5? I see the same result for 'de' culture when inputting 1.5, the...
Jon Skeet
people
quotationmark

, is the NumberGroupSeparator in the UK culture. There's no validation in terms of how many digits are in each group. So "1,2,3" would be parsed as 123, even though that's not how we'd normally expect it to be written. While it would make... more 10/10/2014 2:36:06 PM

people

Format Code MS Visual Studio for C# Console project Not working

Excuse me, I use Ms Visual Studio 2010. I try to follow many suggestion at this case, but I am still failed to make this functionality working well.. This is my code, still not...
Jon Skeet
people
quotationmark

I suspect the problem is in your formatting options. Under Options / Text Editor / C# / Formatting / Indentation, make sure that the "Indent open and close braces" box is not checked. Your code looks like it's formatted perfectly for a... more 10/10/2014 11:30:08 AM

people

How to convert a UTC DateTimeOffset to a DateTime that uses the systems timezone

Quartz.net offers a method to get the next time of the next trigger event: http://quartznet.sourceforge.net/apidoc/1.0/html/html/cc03bb79-c0c4-6d84-3d05-a17f59727c98.htm The docs...
Jon Skeet
people
quotationmark

You can just use the DateTimeOffset.LocalDateTime property: trigger.GetNextFireTimeUtc().Value.LocalDateTime From the documentation: If necessary, the LocalDateTime property converts the current DateTimeOffset object's date and time... more 10/10/2014 9:41:19 AM

people

Find the index of an xml element in text C#

I am making a WPF app which displays XML in a FlowDocument, and a user can select an element or elements in this XML with XPath. I want to be able to highlight the value of the...
Jon Skeet
people
quotationmark

If you're happy to use LINQ to XML instead (it's a generally nicer API) and if knowing the line number and position within the line is good enough, you could use IXmlLineInfo: using System; using System.Xml; using System.Xml.Linq; using... more 10/10/2014 9:35:33 AM

people