Browsing 7239 questions and answers with Jon Skeet

When a lock holds a non final object, can the object's reference still be changed by another thread?

When an object needs to be synchronized, the IDE complains if it's not set non-final (because its reference isn't persistent): private static Object...
Jon Skeet
people
quotationmark

But could a synchronized object's reference also be changed by another thread B while thread A holds the lock for the same object? If you mean "could another thread change the value of the myTable variable, the answer is... more 1/30/2014 2:08:01 PM

people

Type Cast error from lambda to delegate

I have been following this Example to implement LazyLoading, to initialize lazyObject with some value i am making a call to function with the help of Lambda Expression. But, i am...
Jon Skeet
people
quotationmark

New answer with edited question The problem is that your lambda expression isn't valid - you're trying to use collection initializer syntax, but your type isn't a collection. So instead of this: () => new t_user_audit {... more 1/30/2014 1:16:14 PM

people

Can't access protected member of the same base class

I have something like this: class Node { protected Node Parent { get; private set; } } class NodeDerived : Node { void SomeMethod() { Node...
Jon Skeet
people
quotationmark

From the C# 5 spec, section 3.5.3: When a protected instance member is accessed outside the program text of the class in which it is declared, and when a protected internal instance member is accessed outside the program text of the... more 1/30/2014 1:07:23 PM

people

Formatting Numbers as Strings with point in place of Decimals no matter Culture

WinForms, I have a textbox leave event, in the textbox the user is prompted to add a price example: He needs to provide the price in the textbox let's say he writes 5 only, the...
Jon Skeet
people
quotationmark

Just use the overload of decimal.TryParse which takes an IFormatProvider, and specify the invariant culture. Then use that for formatting, too. (I'm assuming you want it to be treated consistently as "dot for the decimal separator" on both... more 1/30/2014 1:01:25 PM

people

new to android understanding HashMap<String,

I have been going through the following tutorial and came across this line of code which I have no idea what it means: HashMap<String, String> map = new HashMap<String,...
Jon Skeet
people
quotationmark

The tutorial is just badly (horribly!) formatted - too many levels of HTML escaping. Someone didn't take nearly enough care over their post... It should look like this: private ArrayList<HashMap<String, String>> data; private... more 1/30/2014 12:31:54 PM

people

Can I replace multiple similar methods with a lambda expression?

I have several functions that takes in list of objects and create a chart Series out of them. It looks repetetive and I feel like I can replace these similar looking functions...
Jon Skeet
people
quotationmark

Yes, you can. At least, you may be able to. For example - having changed the method names to be more conventional, and using generic type inference for the method calls: private static Series GetBuysSeries(List<Order> buys) { ... more 1/30/2014 5:58:57 AM

people

TimeZoneInfo and Daylight Saving

I use TimeZoneInfo.ConvertTime method to convert from source TimeZone to Destination TimeZone. This works fine for me. I want to know, if Daylight Savings has been changed for the...
Jon Skeet
people
quotationmark

Yes, TimeZoneInfo.ConvertTime handles daylight saving time, as best it can. However, note that if you're using a DateTime with a kind of "unspecified" (e.g. having parsed it from a string) that may be ambiguous in your source time zone.... more 1/30/2014 5:53:44 AM

people

How do I reference a specific index of element in an ArrayList?

Let's say I initialize an ArrayList using the following code: ArrayList fib = new ArrayList(); fib.add(18); fib.add(23); fib.add(37); fib.add(45); ...
Jon Skeet
people
quotationmark

I suspect you're looking for List.indexOf: int index = fib.indexOf(45); // index is now 3 indexOf returns -1 if the value isn't found in the list. Note that temp isn't a member of ArrayList, and if you use fib.get(4) it will return 50,... more 1/30/2014 5:41:42 AM

people

Why is C# Rounding This Way?

So, I've got this floating point number: (float)-123456.668915 It's a number chosen at random because I'm doing some unit testing for a chunk of BCD code I'm writing. Whenever I...
Jon Skeet
people
quotationmark

According to MSDN, the range of float is approximately -3.4 * 10^38 to +3.4 * 10^38 with 7 digits of precision. The above number, unless I'm completely missing something, is well within that range, and only has 6 digits after the... more 1/30/2014 3:44:17 AM

people

JUnit test returning null and false

So I am practicing parameterised tests in JUnit. I created this class: public class Operation { public Operation() { } public int add(int value, int num) { ...
Jon Skeet
people
quotationmark

You're not using expected anywhere - not even making it part of the state of the class. Your assertion here: assertTrue(value == o.add(value, num)); ... is not asserting what you want it to. It's only going to work when num is 0. Look... more 1/29/2014 11:26:23 PM

people