Browsing 7239 questions and answers with Jon Skeet

Why the decimals 1.00M and 1.000000M differ in C#

I had a strange problem. I tried to assign a decimal variable to an SAP web service. But I got error CX_SY_CONVERSION_LOST_DECIMALS for decimal place exceeding above the limit....
Jon Skeet
people
quotationmark

Now what is the difference between i and j? i has 6 decimal places of precision; j only has 2. Sure, the difference doesn't change the magnitude of the number at all - and i == j will still return true - but decimal retains the... more 3/12/2014 1:28:11 PM

people

Why is this assignment not thread safe?

I've been reading this book from Joseph Albahari about threading: http://www.albahari.com/threading/ In Part 2, I found this...
Jon Skeet
people
quotationmark

The assignment is atomic in that any reading thread will either see 123 or the previous value - not some intermediate value. However, there's no guarantee that a thread will see the new value until there have been two memory barriers: a... more 3/12/2014 11:37:07 AM

people

how to get inspect element code using c# 2

I want to get text from URL but text is not shown in source code. I can see it only in inspect element . Is there anyway, in C# to get the contents of Inspect element of the page....
Jon Skeet
people
quotationmark

I haven't used the HTML Agility pack myself, but I suspect it's just that your XPath expression is wrong. Try: doc.DocumentNode.SelectNodes("//a[@class='op-to-b-2']/@href") That will get name/value pairs. To get just the values, you can... more 3/12/2014 11:25:47 AM

people

How to compare parsed json value in C#

I am a beginner in c# , I am creating a app in which login page requests PHP file in url and it sends Json data as response I was able to decode the Json data,But the decoded data...
Jon Skeet
people
quotationmark

I suspect the immediate problem is that your pair[1] value still starts and ends with a double quote - so if you print it out you'll see "Value" rather than Value You could just trim them from the start manually, but I would strongly... more 3/12/2014 7:02:52 AM

people

C# How to use get, set and use enums in a class

I have a program where I use a class store settings. I need it to use set and get functions to change and store settings. I have tried this, and I don't get it to work. Can anyone...
Jon Skeet
people
quotationmark

There are several things wrong here: Your enum is private, but your methods are public. Therefore you can't make your methods return type be the enum type, or have parameters with that type Your SetDifficulty method has a parameter of... more 3/11/2014 7:50:07 PM

people

Will floating point operations on the JVM give the same results on all platforms?

I'm using Java in an application running on multiple machines, and all machines need to get the same results for mathematical operations. Is it safe to use Java's floating point...
Jon Skeet
people
quotationmark

Not in general, no. However, you can use strictfp expressions: Within an FP-strict expression, all intermediate values must be elements of the float value set or the double value set, implying that the results of all FP-strict... more 3/11/2014 7:46:41 PM

people

Java unresolved JPanel variable?

Why can't aniPanel be resolved to a variable. I've tried AniPanel aniPanel = new AniPanel(); but this doesn't solve the problem. I've also made sure to import...
Jon Skeet
people
quotationmark

There are various things wrong with your code. Firstly, Java is case-sensitive. Here's your variable declaration: public JPanel AniPanel; And here's where you're trying to use it: aniPanel = new AniPanel(); Note the capital A in the... more 3/11/2014 6:36:16 PM

people

How to extend an object that has a private constructor?

I have a person object that has a private constructor which is coming from an external service. In the constructor the firstname and lastname are taken off of the database. now...
Jon Skeet
people
quotationmark

If a class only has a private constructor, you simply can't derive from it except as a nested type. Basically it sounds like the type you want to use is not amenable to being used in tests :( When you say the type "is coming from an... more 3/11/2014 5:38:26 PM

people

Passing an expression as a parameter

I'm trying to build a generic GroupBy Method, I guess it should be something like this var result = GenericGroupBy<List<DTO>>(dataList, g=>g.Id); public object...
Jon Skeet
people
quotationmark

Currently there are two problems: Your method expects a Func<T, bool> and I suspect g => g.Id fails that because your Id property isn't a bool You're currently specifying List<DTO> as the type argument, when I suspect you... more 3/11/2014 5:12:09 PM

people

Java threads holding a monitor

I was reading about java threads and happened to read this blog. In the blog I came across a statement: During the execution of a synchronized method, the thread holds the...
Jon Skeet
people
quotationmark

It means that a synchronized instance method is broadly equivalent to: public class FooClass { public void foo() { synchronized(this) { ... } } } Whereas a synchronized static method is broadly... more 3/11/2014 1:48:12 PM

people