Browsing 7239 questions and answers with Jon Skeet

Avoiding multiple "if" statements when iterating a list of objects c#

I have various classes which generate excel graphs. Each class generates a different graph. They all share the same private variables, with different values. I wish to write a...
Jon Skeet
people
quotationmark

They all share the same private variables, with different values. They should all implement the same interface, which exposes the ImageFile property. For example: public interface IGraph { // TODO: Consider making this read-only... more 10/2/2013 8:54:05 AM

people

System.Threading.ThreadAbortException occurred in mscorlib.dll occuring persitently

Im new to .net, Im using the following code to transfer from gridview to excel: protected void toexcelbutton_Click(object sender, EventArgs e) { ...
Jon Skeet
people
quotationmark

Yes, it will happen due to this: Response.End(); As documented: To mimic the behavior of the End method in ASP, this method tries to raise a [ThreadAbortException] exception. If this attempt is successful, the calling thread will be... more 10/2/2013 7:17:00 AM

people

Is class a singleton or not . how to make a class as a singleton or a prototype in Spring

By default a class is singleton or not .. public class You{ } public class My(){ public static void main(String a[]){ You you=new You(); } } is you object is singleton...
Jon Skeet
people
quotationmark

No, it's not a singleton. You can create multiple instances: You you1 = new You(); You you2 = new You(); A singleton class enforces only a single instance being created, usually by including a private constructor, and a static method to... more 10/2/2013 6:51:53 AM

people

Linq statement return error when no record found

THe linq statement below return an exception error when no match record found. Is there anyway to handle this?, Please advise, thank you AdventureEntities hem = new...
Jon Skeet
people
quotationmark

No, that shouldn't throw an exception. It will, however, set list to null - because that's what FirstOrDefault does when there are no results. If you then dereference list, you'll get a NullReferenceException. You can avoid this by just... more 10/2/2013 6:29:25 AM

people

Does Java use the one byte long ASCII Code set for character representation?

I'm just starting with Java and trying to understand the basic concepts. I was asked the question, "Does Java use the one byte long ASCII Code set for character...
Jon Skeet
people
quotationmark

ASCII is a 7-bit representation, so yes, every ASCII character can fit in a byte. However, a Java char is 16 bits. It's a UTF-16 code unit. So if you have a char array of 100 characters, that will require 200 bytes (plus object overhead)... more 10/1/2013 8:58:07 PM

people

.net vs Objective c SHA 512 mismatch

I am trying to write function for creating sha512 string in objective from .net function which is public static string GetSHA512(string strPlain) { UnicodeEncoding UE = new...
Jon Skeet
people
quotationmark

In the Objective C version you're converting the text to binary using UTF-8. In the .NET version you're using UTF-16. That may not be the only difference, but it's certainly a relevant one. I'd rewrite your .NET method as: public static... more 10/1/2013 7:28:37 AM

people

final array instance variable in a java class and resetting a reference

I tried out the following code,which has a final instance variable called data.This is instantiated in the constructor using an int[] argument.If an element of the int[] array...
Jon Skeet
people
quotationmark

This has nothing to do with data being final, or a field elsewhere. You can see the exact same effect much more simply: int[] x = { 1, 2, 3, 4, 5 }; int[] y = x; y[0] = 10; System.out.println(Arrays.toString(x)); // 10, 2, 3, 4, 5 y =... more 10/1/2013 7:01:55 AM

people

Constructor in class cannot be applied to given types. Hope for assistance

I'm fairly new to Java and I'm using BlueJ. I keep getting the error: constructor ItemNotFound in class ItemNotFound cannot be applied to given types; required: int found: no...
Jon Skeet
people
quotationmark

The ItemNotFound class only has one constructor: one that takes an int parameter: public ItemNotFound(int id) You're trying to call that without any arguments: throw new ItemNotFound(); That's not going to work - you need to pass an... more 10/1/2013 6:39:23 AM

people

Java reflection nested methods not modifying underlying object

I am taking in an array of methods and I want to chain them together to modify an object that I am working in. For example I start...
Jon Skeet
people
quotationmark

Your general approach should be fine (although your approach to parameter conversion is somewhat ugly) - it's the specifics that are presumably causing you problems. Here's a short but complete program demonstrating calling methods and... more 10/1/2013 6:36:48 AM

people

Object reference not set to an instance of an object, xelement to listview

private void ButtonRequest_Click(object sender, EventArgs e) { XmlDocument xml = new XmlDocument(); XmlDocument request = new XmlDocument(); ...
Jon Skeet
people
quotationmark

You're using FirstOrDefault(), which will return null if it doesn't find any values - but you're then unconditionally dereferencing that return value. If you do want to handle the case where you don't get any values, just use a cast to... more 10/1/2013 6:22:23 AM

people