Browsing 7239 questions and answers with Jon Skeet

C# Right usage for (number & number) from C++?

I have the following C++ lines: if(fromPos.x == 0xFFFF){ if(fromPos.y & 0x40){ fromIndex = static_cast<uint8_t>(fromPos.z); } else{ ...
Jon Skeet
people
quotationmark

In C++, the condition in an if statement doesn't have to be a Boolean expression - but it does in C#. You just need to check for the result being non-zero: if ((fromPos.y & 0x40) != 0) (The brackets are required due to precedence;... more 10/19/2014 7:16:50 AM

people

string.Format(…, double) followed by double.Parse using same NumberFormatInfo results in FormatException. Why?

NumberFormatInfo nfi = new NumberFormatInfo() { CurrencySymbol = "$$s. ", CurrencyGroupSeparator = ".", CurrencyDecimalSeparator = ",", NegativeSign = "-", ...
Jon Skeet
people
quotationmark

You're not telling it that it should accept a currency value. To do that, you need to call an overload which accepts a NumberStyles value, and include NumberStyles.AllowCurrencySymbol. For example: using System; using... more 10/18/2014 5:10:34 PM

people

Comparison vs. Double.MaxValue

When comparing vary large doubles it happens that the following test fails: [Test] public void DoubleMaxValueTest() { double val = Double.MaxValue; double epsilon =...
Jon Skeet
people
quotationmark

To answer the final question, as it sounds like you actually understand why the test fails... IEEE-754 has a neat property that if you take adjacent bitwise values, those end up being adjacent representable double values. So you can find... more 10/18/2014 4:42:16 PM

people

having trouble with passing array

I'm having issues with passing array values. I've been working on this for hours and can't seem to find the answer. wonder if someone can point me in the right direction. This is...
Jon Skeet
people
quotationmark

There are two problems - one explaining why you're only using the first input number, and one explaining why you're only comparing it against one random number. For the random number part, here's the problem: Seed =... more 10/18/2014 4:16:38 PM

people

decimal issue when adding a flat fee

I have a small issue I believe the code is doing exactly what its suppose to be doing I have a function whereby I pass in an amount and I add a flat fee of 40 cents to it for the...
Jon Skeet
people
quotationmark

You're not using decimal - you're using double. Use decimal everywhere (so moneyIn should be a decimal too). If you're actually using 999.00m for moneyIn, that would make it a decimal and your current code wouldn't even compile (as there... more 10/18/2014 9:52:43 AM

people

Access Google drive spreadsheets with drive API

I am wanting to make a web application which uses the Google Drive API to access a friend's spreadsheet located on his Google Drive. It will be reading/writing to the sheet but...
Jon Skeet
people
quotationmark

I've just tried the code in the quickstart guide and it worked without any problems at all, using the Google.Apis.Drive.v2 nuget package. As you say, there are lots of different approaches to auth and the code in the quckstart isn't... more 10/18/2014 7:40:15 AM

people

Problems assigning variable to the return of a function

I have been searching online for solutions to this problem for hours, but cannot find one. I am a beginner with java so I don't understand many of the errors and this is why I...
Jon Skeet
people
quotationmark

Just remove the int part of int sumOfGames += value; So it becomes sumOfGames += value; You can't use a compound assignment operator in a variable declaration - the whole point of a compound assignment operator is that it uses the... more 10/17/2014 4:37:27 PM

people

getting unassigned variable error on a variable that is assigned

userInput is assigned so im not sure why I get error. I've already sifted through the similar questions, googled, binged and didnt find what I was looking for. ps new to...
Jon Skeet
people
quotationmark

Here's the problematic code: userInput = getUserInput(userInput); userInput is assigned after that statement, but think of it this way: int tmp = getUserInput(userInput); userInput = tmp; Nothing has assigned a value to userInput... more 10/17/2014 3:39:09 PM

people

C# Creating an overloaded method where one int uses a fixed value and the other receives a value

I am trying to set the value of an overloaded method to 1, but I want the original to remain uninitialised. public void Method1(string string1, decimal decimal1, int...
Jon Skeet
people
quotationmark

The problem is that you've got two methods with the same signature. The simplest fix to this is just to remove the final parameter from the second overload, and just call the first overload with a hard-coded value for the last... more 10/17/2014 2:19:24 PM

people

Interrupt current thread inside run() doesn't throw InterruptedException

I made a simple function to test interrupt() & InterruptedException in Java: public static void main(String[] args) { checkInterrupt(); } private static void...
Jon Skeet
people
quotationmark

You'll get an InterruptedException if the thread calling join is interrupted while waiting for the other one to die. That's not what happens in your case - you're interrupting the thread you're joining which is an entirely different... more 10/17/2014 12:52:11 PM

people