Browsing 7239 questions and answers with Jon Skeet

Adding attribute to XML Node always fail

I always get exception below when try to add attribute, why it's not working? The prefix '' cannot be redefined from '' to 'http://ws.plimus.com' within the same start...
Jon Skeet
people
quotationmark

This simplest approach is to let LINQ to XML do this automatically by specifying the namespace in the element name: XNamespace ns = "http://ws.plimus.com"; var docXml = new XElement(ns + "param-encryption", new XElement(ns +... more 12/23/2014 12:23:30 PM

people

Removing Element from XML in C#

below is the xml and i need to remove the Element SMS where code equals to "ZOOMLA". i am using C# code as below but it does not work. and gives me "object reference error" ...
Jon Skeet
people
quotationmark

You're currently looking for a Code attribute, whereas in your XML it's an element. So FirstOrDefault() doesn't find anything and returns null, hence the exception on the next statement. Additionally, you can just use the LINQ to XML... more 12/23/2014 11:50:39 AM

people

creating objects with same name as class in java

In C++ when I create an object like the following, then no more objects can be created for the same class. Box Box; //Box is the class Name Here Box becomes an object and...
Jon Skeet
people
quotationmark

Basically, Java has slightly different set of syntax rules, by the sounds of it. When the grammar says you've got a variable declaration with an initializer, such as this: Box box = new Box(); ... it knows that Box has to be the name of... more 12/23/2014 10:19:30 AM

people

Dynamic Linq Group By UnixTime

I am using Dynamic Linq. Group By works fine like this: var groupedData = resultSet.AsQueryable().GroupBy("Username", "it").Select("new (it.Key as key, it.Count() as...
Jon Skeet
people
quotationmark

I would try to get out of the dynamic part as quickly as possible. You can then convert to DateTime and use the Date part for the grouping. If you need to be dynamic in the field name, you can do that, but end up with an... more 12/23/2014 9:34:43 AM

people

Linq with dynamics "where parameter"

I have this case: I create an array from a list like this: String[] parameters = stringParametersToSearch.Split(' '); The number of parameters can vary from 1 to n and I have...
Jon Skeet
people
quotationmark

You either want to use Any or All, depending on whether you want to find objects where all of the parameters match or any of them. So something like: var result = components .Where(o => parameters.Any(p =>... more 12/23/2014 8:34:09 AM

people

Why aren't method references singleton?

In Java, the following code returns false on both queries. Why? Wouldn't it be simpler for method references to be singleton? It would certainly make attaching and detaching...
Jon Skeet
people
quotationmark

For instance methods, I don't think it would make sense for them to be cached. You'd have to cache one method per instance... which would either mean an extra field within the class associated with the method - one per public method,... more 12/23/2014 8:26:08 AM

people

tryLock method non blocking method?

The documentation of the tryLock method says that it is a non-blocking method which allows you to obtain/acquire the lock (if that's possible at the time of calling the method). ...
Jon Skeet
people
quotationmark

Acquiring the lock implies that you're trying to access a guarded section of code so it should block (if you're not lucky i.e. you should block at least in certain scenarios) If that's the behaviour you want, you should just use the... more 12/22/2014 12:47:21 PM

people

understand MSIL of try catch finally

I have the following code using System; class Pankaj { public static int Main() { int returnValue=0; try { return returnValue; ...
Jon Skeet
people
quotationmark

Why the try catch is again included inside the try block. Not sure on this one. It may just be the way that ildasm chooses to decompile it. ECMA-335 says there are restrictions on how SEHClause elements can be specified after a... more 12/22/2014 11:34:35 AM

people

Open file, read as hex and convert it to ASCII?

Is it possible to read a file hex values into c# and output the corresponding ASCII? I can view the file in a hex editor which I can then see the appropriate ASCII next to the hex...
Jon Skeet
people
quotationmark

It sounds like you just need: string text = File.ReadAllText("file.txt"); There's no such thing as "hex values" in a file - they're just bytes which are shown as hex in various editors geared towards editing non-text files. The above... more 12/22/2014 9:39:58 AM

people

What does new [] mean

There is a code where that reads something from the XML and loads it into dictionary. Pls find the code below. I need to understand what new [] {header} does. what is new []...
Jon Skeet
people
quotationmark

It's an implicitly typed array creation expression - it lets the compiler infer the array type, a bit like using var but for arrays. So in your case, it's equivalent to: _dict.Add("Header_" + headerId, new XmlNode[] { header }); It was... more 12/22/2014 8:44:48 AM

people