Browsing 7239 questions and answers with Jon Skeet

Creating a List<T> inside a method leaves it null outside why?

I have a C# class that does some parsing of XML passed in to its one public method. The idea is that the method pulls info out of the XML, creates objects and sets up collections...
Jon Skeet
people
quotationmark

I thought that passing a reference type, such as a List< to a method allowed the method to modify the type, and have those changes seen outside the method You're getting confused with passing a parameter by reference (using the ref... more 3/30/2014 3:33:12 PM

people

Retrieve previously stored byte array c# in the same format

I'm developing a winform C# application with SQLCe database. When I'm uploading the image (and displaying it to PictureBox) OpenFileDialog open = new...
Jon Skeet
people
quotationmark

This is the problem: return Encoding.ASCII.GetBytes(dt.Rows[0][0].ToString()); You're converting the value to a string. It's not text data - just don't do it! I would expect you to be able to just cast the value to byte[]: return... more 3/30/2014 3:14:56 PM

people

c# change ElementName

I have the following class: [Serializable] public class UniversalRequest { [XmlElement(ElementName ="TEMP")] public string Item { get; set; } } and I would like to...
Jon Skeet
people
quotationmark

I would like to change the ElementName of Item dynamically Attributes in .NET really aren't designed for that. The idea is that they're compile-time metadata. If you want more dynamic metadata, you'll need to take a different... more 3/30/2014 2:58:13 PM

people

C# Reflection : Finding Custom Attributes on a Class Property

I would like to define a custom attribute for specific properties of a class. Based on reflection it should be possible to check if the property is annotated with this attribute...
Jon Skeet
people
quotationmark

Your attribute is being applied to the properties. While you do have fields, they're created by the compiler - and your custom attribute isn't being applied to them. Your code is broadly equivalent to: [CompilerGenerated] private... more 3/30/2014 1:40:53 PM

people

Eclipse project "save as"

I'm quite new to android programming and I was wondering if there is a Save As button in Eclipse for the entire project instead of saving only 1 XML or Java at a time. For...
Jon Skeet
people
quotationmark

For example, when I work on excel, sometimes I like to save different versions of excel workbooks so that I can roll back if there is a problem. Learn to use a good source control (version control) system. That's a much cleaner... more 3/30/2014 1:35:46 PM

people

Reading a random entry from XML in Windows Phone

I'm writing my first app for Windows Phone and I encountered a problem. I've created a button that is supposed to generate a random entry from my XML on the textblock. The XML...
Jon Skeet
people
quotationmark

I would structure the code very differently: Create a class for both the type and description Don't use all those if statements - you're doing basically the same thing in every situation. You can always use a HashSet<string> for... more 3/30/2014 12:21:21 PM

people

Java: "Missing return statement"

I've having some trouble with recursion. At the moment, this code gives me an error message "missing return statement". Any way to get this working the way I want it to? I want it...
Jon Skeet
people
quotationmark

Currently, you have this statement: power2(n, x, count); ... which ignores the result completely. In that branch, we never return anything from the method call. I suspect these two issues are linked. I suspect you just want: return... more 3/29/2014 7:45:41 PM

people

How to discover through Reflection the base base base class from a class?

I have the following scenario: public class BaseEntity { public int Id { get; set; } } public class BaseAcademicEntity : BaseEntity { ... } public class BaseFinancialEntity...
Jon Skeet
people
quotationmark

The simplest way is to use Type.IsAssignableFrom: if (typeof(BaseEntity).IsAssignableFrom(type)) more 3/29/2014 7:22:11 PM

people

java unicode value of char

When I do Collection.sort(List), it will sort based on String's compareTo() logic,where it compares both the strings char by char. List<String> file1 = new...
Jon Skeet
people
quotationmark

My understanding is char means it specifies the unicode value, I want to know the unicode values of char like ,(comma) etc Well there's an implicit conversion from char to int, which you can easily print out: int value =... more 3/29/2014 6:53:59 PM

people

use cat to send input file to java main class

If i want to input file say myfile.txt using cat command say "cat myfile.txt java myMain" What should I write in myMain function ? Is myfile.txt stored directly in args[0] or...
Jon Skeet
people
quotationmark

You wouldn't do it quite like that - that's currently redirecting to a file. You either want to pipe it to java, or redirect in the other way: java Foo < myTextFile or cat myTextFile | java Foo Next, you should use System.in, as... more 3/29/2014 4:27:55 PM

people