Browsing 7239 questions and answers with Jon Skeet

C# Linq List in other list

I have 2 string lists List<string> listA listB I need to know if all of listB is in listA. listA is the bigger list and we need to make sure all of listB is in it. Is...
Jon Skeet
people
quotationmark

No, it's not a union. The simplest approach is to check whether there's anything in listB which isn't in listA: var result = !listB.Except(listA).Any(); In other words, if you took everything from listA away from listB, would there be... more 8/14/2014 6:44:17 PM

people

java basics System.out.print

I have the following code: class Baap { public int h = 4; public int getH() { System.out.println("Baap " + h); return h; } } public class Beta...
Jon Skeet
people
quotationmark

Method arguments are always completely evaluated before the method is called. So this line: System.out.println("testing" + b.getH()); is evaluated as: String lhs = "testing"; String rhs = b.getH(); String argument = lhs +... more 8/14/2014 4:21:38 PM

people

Why is this LINQ not finding an element two levels down?

I am having trouble parsing the XML file (stripped down sample of XML in code snippet below). The error I am getting is An unhandled exception of type...
Jon Skeet
people
quotationmark

As you say, you're not drilling down to the Barcodes element under OrderItem. Don't forget that el will refer to an Order element, but you want the Order -> OrderItems -> OrderItem -> Barcodes -> Barcode element. I suspect you... more 8/14/2014 3:14:36 PM

people

Deserialize stringified JSON object

I've read a few posts on how to do this, but everything that i've seen the JSON object has specific property names to query, where i do not. Here is my JSON string: { ...
Jon Skeet
people
quotationmark

If you use LINQ to JSON it's simple, because JObject allows you to iterate over all the key/value pairs - it implements IEnumerable<KeyValuePair<string, JToken>>: using System; using System.IO; using... more 8/14/2014 12:34:23 PM

people

How to convert XML from Latin 2 to UTF 8 in Android/C#/Xamarin

I have a problem. In my app i download XML file from the Web. Its encoding is ISO-8859-2. I put some data from this XML to Spinner and there are questions marks instead of some...
Jon Skeet
people
quotationmark

Your GetPageAsString method is broken, basically - it's assuming that the encoding is UTF-8, as that's what StreamReader uses by default. I would strongly urge you to avoid performing the string decoding yourself. In order of preference... more 8/14/2014 10:55:52 AM

people

Type of conditional expression cannot be determined because there is no implicit conversion between `string' and `int'

I have an application that asks the user a set of questions and then receives answers to those questions and then stores them. I also have a problematic line of code where the...
Jon Skeet
people
quotationmark

I strongly suspect that this: correctCount1 > 1 || correctCount1 == 0 ? "s" : incorrectCount1 should be: correctCount1 > 1 || correctCount1 == 0 ? "s" : "", incorrectCount1 After all, you don't really want it to say: "You have... more 8/14/2014 10:28:32 AM

people

java simple date pattern TO oracle sql date pattern

I have following web application: Users can enter java simple date format patterns and a date (of course matching to the java simple date format pattern) and I want to store...
Jon Skeet
people
quotationmark

Therefore I need to translate the java simple date format pattern into the oracle pattern No, you don't. You should instead use a PreparedStatement, and call setDate or setTimestamp on it to specify the value you're interested... more 8/14/2014 8:29:24 AM

people

Should I return empty or nullable array?

I have a public method which searches for an image and if the image exists, it returns it as a byte array. What the method should return, if the image doesn't exist? (the image...
Jon Skeet
people
quotationmark

I would return null (just as a byte[] - all arrays are reference types). Returning an empty array will lead the caller to think they can try to load that data as an image - which they can't. Returning a null reference makes it very easy to... more 8/14/2014 7:28:40 AM

people

static variable behavior in two different application

Two applications are running in a server. That means two EAR are present in server. Now these two application has same jar within it. The jar has one static variable which is used...
Jon Skeet
people
quotationmark

You haven't said which server you're using, but typically an application server has multiple classloaders involved - some shared, and some per-application. The Tomcat documentation has a good explanation of its classloaders, for... more 8/14/2014 6:19:31 AM

people

Calling Enumerable.Join on a IEnumerable collection causes segmentation fault

I have a class Person: public class Person { public string Name {get; set;} public string Surname {get; set;} public uint Age {get; set;} public Person(string...
Jon Skeet
people
quotationmark

So I can imagine that Linq is calling GetEnumerator() many times No, that's not the case. The problem is in your implementation of IEnumerable, notably here: public IEnumerator<Person> GetEnumerator() { return... more 8/13/2014 8:38:48 PM

people