Browsing 7239 questions and answers with Jon Skeet

How to Convert XElement to XComment (C#)

My first question here... I'm parsing xml file (using c# as Xdocument) and trying to disable some xElement objects. the standard way (where I work) is to make them appear as...
Jon Skeet
people
quotationmark

Well it's not quite as you were asking for, but this does replace an element with a commented version: using System; using System.Xml.Linq; public class Test { static void Main() { var doc = new XDocument( ... more 12/15/2014 8:48:28 AM

people

Get node attribute xml C#

I am trying to get all the nodes from an xml file, but I cannot get the node having attributes such as Home and Work. Well, in my case I can get phone Home but not phone Work. ...
Jon Skeet
people
quotationmark

You need to use the Attribute method to get at an attribute. You'll need to query for Phone elements with a Type attribute of Home. For example: Console.WriteLine("Home: {0}", employee.Elements("Phone") .Single(x =>... more 12/15/2014 8:09:57 AM

people

Working with arrays in c#

My question should be simple, im working on a program that has an array contains , ID,name,Money. So i separated the arrays to be easier to work with (search, add etc...) But i...
Jon Skeet
people
quotationmark

Firstly - these are lists, they're not arrays. If they were arrays, they would be things like string[] and int[]. However, you definitely shouldn't have all these separate lists. Instead, work out what the relevant types are - it's not... more 12/14/2014 5:39:18 PM

people

Renaming class field value in Java

Hey I need change uuid value via getClass(), here is my code but I don't know what obiect I must type instead UUID Field uuidField =...
Jon Skeet
people
quotationmark

If you want the equivalent of c.uuid = newUuidValue; but with reflection, you just want: uuidField.set(c, newUuidValue); The first argument to set is a reference to the object whose field you want to modify. more 12/13/2014 11:17:24 PM

people

Cast object (type double) to int

Okay, so if I have this code double a=1.5; int b=(int)a; System.out.println(b); Everything works fine, but Object a=1.5; int b=(int)a; System.out.println(b); gives the...
Jon Skeet
people
quotationmark

When you're casting from Object, you're unboxing from the wrapper type... and you can only unbox to the original type, basically. It's effectively a cast to the relevant wrapper type, followed by a call to the appropriate xxxValue method.... more 12/13/2014 2:30:04 PM

people

OleDbCommand, two sequential "using"

With two sequential "using", will both connections be disposed when exiting from {}? using(OleDbConnection con = new OleDbConnection(conString)) using(OleDbCommand command =...
Jon Skeet
people
quotationmark

There's only one connection there - and a command using the same connection. Both will be disposed. This is effectively: using(OleDbConnection con = new OleDbConnection(conString)) { using(OleDbCommand command = con.CreateCommand()) ... more 12/13/2014 2:27:11 PM

people

How to create an ArayList with a different name each type?

I am new to programming and I am currently learning Java. I am using ArrayList to create string arrays to store messages to specific "accounts" in this case. Whenever some...
Jon Skeet
people
quotationmark

I'd first advise you to take note of the fact that you're referring to these objects as accounts - that suggests you should quite possibly have an Account type, which contains the List<String> of messages. Aside from anything else,... more 12/12/2014 8:01:24 PM

people

array of objects initialization compiler error

public class pes{ public static void main(String args[]){ Computer[] c=new Computer[3]; Computer c[0]= new Computer("Jayu",66,10,20,30,40,50); for(int...
Jon Skeet
people
quotationmark

The Computer part in your assignment is invalid - you're trying to declare anything. It should just be: c[0] = new Computer(...); At that point it will compile - but you'll get a NullPointerException when i is 1. You'll need to either... more 12/12/2014 6:34:53 PM

people

SimpleDateFormat adding 7 hours?

I'm trying to do a simple subtraction of dates and getting odd results. For some reason when I format it with SimpleDateFormat, there are 7 extra hours difference. package...
Jon Skeet
people
quotationmark

The "12-7 = 5" is definitely related to the problem... or more accurately, it's "12-5=7", i.e. 5 hours before midnight is 7pm. You'll see that if you format it as a full date/time: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd... more 12/12/2014 3:28:37 PM

people

Is it possible to get the encrypted form of a value that has just been encrypted using .NET Rijndael

I want to encrypt and decript small snippets of data. The data will be stored locally in a cookie, and remotely, in the database, in encrypted form. So, after the data value is...
Jon Skeet
people
quotationmark

The simplest way of doing this would be just to use a MemoryStream Encrypt to the MemoryStream Close the writer at the end, to make sure everything's flushed Call MemoryStream.ToArray to get the encrypted data Write the encrypted data to... more 12/12/2014 3:03:31 PM

people