Browsing 7239 questions and answers with Jon Skeet

How to get multiple elements by name in XML using LINQ

I've the below XML: <?xml version="1.0" standalone="yes"?> <TestSuite> <TestCase Name="XXX" ID="123;234; 345; 456"> <CodeBlock /> ...
Jon Skeet
people
quotationmark

It's not clear why you're grouping at all... and you just need to split the values and flatten that with SelectMany, by the looks of it: var separators = new[] { ';', ',' }; var r = xdoc.Descendants("TestCase") .Select(x =>... more 4/22/2014 6:10:38 AM

people

sending two strings , but receiving one over tcp

Hy guys, this is how my client and server code looks like: Client: TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse("192.168.1.12"), 5004); ...
Jon Skeet
people
quotationmark

The problem is that you're using a stream-based protocol (TCP/IP) as if it were a message-based protocol. It's not. There are a few options here, but the simplest are: Write a delimiter after each message Write a length-prefix (the... more 4/21/2014 4:40:30 PM

people

Unparsable Date Exception : SimpleDateFormat

am getting date as string String dateStr = Mon Mar 31 2014 00:00:00 GMT+0530 (India Standard Time) but am getting unparsable date exception when am tring to parse using...
Jon Skeet
people
quotationmark

The "GMT" part is confusing things - the Z format specifier expects just "0800" or similar. You can change your format to: "EEE MMM dd yyyy HH:mm:ss 'GMT'Z" and that will work. (It's ignoring the time zone name at the end of the... more 4/21/2014 10:05:09 AM

people

Java memory leaks with classes

I am wondering if the following piece of code is a memory leak, since Google is only turning up weird examples. Basically, if I have a class Tree: public class Tree{ ...
Jon Skeet
people
quotationmark

Will all the 100 allocated Birds be taken care of WITH the tree class by the garbage collector? Well, your code doesn't actually create any instances of Bird. It just creates an array, and every element of that array will be null to... more 4/21/2014 10:01:59 AM

people

Converting dd/MM/yyyy input to yyyy MM dd in date format not varchar/datetime

After searching for a full day, I'm unable to find a solution, facing multiple conversion errors. Main objective is to convert a dd/MM/yyyy to yyyy-MM-dd "date" format to fit in...
Jon Skeet
people
quotationmark

Main objective is to convert a dd/MM/yyyy to yyyy-MM-dd "date" format to fit in SQL Don't! You should avoid string conversions as far as you possibly can. Keep your data in its natural representation for as much of the time as you... more 4/21/2014 9:44:53 AM

people

NumberFormat.getCurrencyInstance() turning everything to zero?

I've been working on this for hours and can't find a solution... When I use this code: NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(Locale.US); ...
Jon Skeet
people
quotationmark

The problem isn't in the size of the double you're using, but the precision. A double can only store 15-16 digits of precision, even though it can hold numbers much bigger than 1016. If you want exact decimal representations - and... more 4/21/2014 9:04:22 AM

people

ContainsKey of HashMap does not work with a Custom Class as key

I have a custom class MarioState that I want to use in a HashMap. The class represents a possible state in a state space of the Mario game. Below is a simplified version of the...
Jon Skeet
people
quotationmark

Your hash code computation and equality comparison are both based on stuck - but that can change over time. If you mutate an object after adding it as a key within a hash map, in such a way that the hash code changes, then the key will... more 4/20/2014 12:14:47 PM

people

Object lost data while sending through socket

Im trying to send an object back and forth between a client and server and when it leaves the client, all the data is there, i.e z = 6.0 but when it reaches the server, all the...
Jon Skeet
people
quotationmark

You're repeated sending the same object via serialization - and ObjectOutputStream notices that, and instead resolves this to references to the same object. If you want to effectively send a separate object on each call, add this to your... more 4/19/2014 7:22:19 PM

people

Something weird in Visual Studio Debugger

I have some class with private member _stuffs which is of type IStuffs an interface. When I set a break point just before getting out of the constructor, when debugging and...
Jon Skeet
people
quotationmark

Look carefully at your constructor: public MyModelApp(object parent) : base(parent) { IStuffs _stuffs = new MyStuffs(this); } You're declaring a local variable called _stuffs and giving it a value. That is not the same as the... more 4/19/2014 7:09:24 PM

people

is String created by literal primitive or referenced type?

i'm already tired but i'm wondering if (see the topic). String a = "first"; String b = "second"; a = b; b = "third"; System.out.println(a + ", " + b); -my...
Jon Skeet
people
quotationmark

Isn't is String referenced type? Yes, String is a reference type. So after command "a = b;" why didnt change both of variables? Because you only said to change the value of one variable at a time. This statement: b =... more 4/19/2014 6:54:10 PM

people