Browsing 7239 questions and answers with Jon Skeet

Delete Element in XML

I try to delete an element in Xml but currently im just removing the "sub-element" XML: <dependency> <dependentAssembly dependencyType="preRequisite"> ...
Jon Skeet
people
quotationmark

Two options. You could select the parent node to remove: xml.Descendants() .Where(x => x.Name.LocalName == "dependentAssembly" && (string)x.Attribute("dependencyType") == "install") .Select(x =>... more 8/6/2014 6:44:09 AM

people

Two dimensional C# Array initialized with 2 other arrays

I'm a bit new to C# and I don't understand how to make this work: private static readonly Unit[,] UNIT_TYPES = new Unit[,]{LENGTH_UNITS, ANGLE_UNITS}; private static readonly...
Jon Skeet
people
quotationmark

You're trying to initialize a rectangular array - whereas what you're providing would be more suitable as a jagged array. A rectangular array is a single array with multiple dimensions - whereas a jagged array is an array of arrays - i.e.... more 8/5/2014 8:36:18 PM

people

Random Number Generator Generates Same Numbers on Android

I have recently started learning about programming mobile applications. I was doing some practice, writing basic programs. First of all I am using LibGDX, so first I test my...
Jon Skeet
people
quotationmark

You should initialize the Random() instance outside your loop - or ideally, just once. (The documentation states that it's thread-safe, so you shouldn't need one per thread or anything like that.) Basically, it's seeding a new instance of... more 8/5/2014 8:13:57 PM

people

How do I make the weird characters in Spanish go away? It persists even after changing JDB URL to UTF 8

I see words such as súbito, autónomo. Why aren't they proper. I had a problem while entering all Russian characters via JDBC into the MySQL database. The problem there was that...
Jon Skeet
people
quotationmark

Well this is probably the first problem: InputStreamReader reader1 = new InputStreamReader(in); That's loading the file using the platform default encoding, which may or may not be appropriate for the file in question. Likewise... more 8/5/2014 2:39:33 PM

people

Need certain LINQ command using let

I want to transform a foreach loop into LINQ. The code looks like this: foreach (XmlNode localNode in localXmlNodeList) { var localKeyNode =...
Jon Skeet
people
quotationmark

You can use let in a foreach loop: // Query modified slightly to make more sense... foreach (var X in from X in Y let varA = X.A let varB = X.B where method(varA, varB) ... more 8/5/2014 2:25:46 PM

people

Structs not being initialized

Today, I figured out it might be interesting to have some sort of enumeration in C# similar to the class enums in Java (which has been done numerous times) but as immutable...
Jon Skeet
people
quotationmark

There are two problems here: You're using the implicit conversion from int when you're initializing the fields... that expects the value to already be there. You should be using the constructor instead. So this: public static readonly... more 8/5/2014 11:46:11 AM

people

Java references not updated

I have the following code List<String> strings = new ArrayList<String>(); strings.add("a"); strings.add("b"); strings.add("c"); for (String s : strings) { s =...
Jon Skeet
people
quotationmark

In the loop I assign a new Object to the reference Well, you assign a new reference as the value for s. s is just a local variable though, which was initialized with the value of the element. It's not tied to the element in the list... more 8/5/2014 11:16:11 AM

people

Comparing dictionaries and creating new dictionary with values in C#

I have two dictionaries Dic A & Dic B. Dic A & Dic B have same keys . I would like to move the values in both the dictionaries into a new dictionary (with Value from Dic...
Jon Skeet
people
quotationmark

That sounds like a join on the two original ones, followed by a conversion: var merged = dicA.Join(dicB, pair => pair.Key, pair => pair.Key, (a, b) => new { Key = a.Value, Value = b.Value }) ... more 8/5/2014 11:07:41 AM

people

Display double value without scientific notation

I have a null able double value which get values from data base.It retrieve value from data base as '1E-08'. I want to display the value with out scientific notification...
Jon Skeet
people
quotationmark

You're calling string.Format with a string. That's not going to apply numeric formatting. Try removing the second line: double? valueFromDB = 1E-08; string formattedString = String.Format("{0:N30}", valueFromDB.Value); Or alternatively,... more 8/5/2014 9:48:30 AM

people

Iterate .net constructor agruments

I am possibly asking the impossible but I shall ask anyway. From the following: public SomeClassConstructor(SomeOtherClass someOtherClass, string someString){ ... } Is it...
Jon Skeet
people
quotationmark

No, you can't access parameter values via reflection. You can get the names, types, attributes etc - but not the values. That's true of methods, constructors, property setters, indexers etc. You could potentially do it in a debugger API,... more 8/5/2014 9:23:47 AM

people