Browsing 7239 questions and answers with Jon Skeet

C# (Unity 4.3) Cannot implicitly convert type `ShotScript[]' to `ShotScript'

Thanks all! The issue was I was using GetComponents rather than GetComponent, thanks! I am fairly new to programming and I am trying to make a 2D game in Unity. I have found a...
Jon Skeet
people
quotationmark

Well this is the problem: ShotScript shot = collider.gameObject.GetComponents<ShotScript>(); It sounds like GetComponents<ShotScript> is returning an array of ShotScript references, i.e. its return type is ShotScript. Do... more 1/18/2014 6:28:20 PM

people

find element in xml, and take other element value

My xml look like: <CURRENCIES> <LAST_UPDATE>2014-01-17</LAST_UPDATE> <CURRENCY> <NAME>Dollar</NAME> <UNIT>1</UNIT> ...
Jon Skeet
people
quotationmark

Your query is over CURRENCIES elements, and you're only looking at the first CURRENCY child. Then you're looking for a RATE child within CURRENCIES rather than CURRENCY. Additionally, you're getting a sequence of integers - and that isn't... more 1/18/2014 3:31:23 PM

people

Differences between mult and div operations on floating point numbers

Is any difference in computation precision for these 2 cases: 1) x = y / 1000d; 2) x = y * 0.001d; Edit: Shoudn't add C# tag. Question is only from 'floating-point' point of...
Jon Skeet
people
quotationmark

No, they're not the same - at least not with C#, using the version I have on my machine (just standard .NET 4.5.1) on my processor - there are enough subtleties involved that I wouldn't like to claim it'll do the same on all machines, or... more 1/18/2014 12:04:55 PM

people

Error in actionPerformed?

I'm trying to create a button for importing CSV file and I'm getting this error: actionPerformed(java.awt.event.ActionEvent) in cannot implement ...
Jon Skeet
people
quotationmark

Well yes - look at the declaration of the method you're implementing: void actionPerformed(ActionEvent e) It isn't declared to throw any checked exceptions. So you can't add a checked exception such as IOException with a throws clause.... more 1/18/2014 11:25:52 AM

people

LINQ to XML with multiple namespaces

I hope you can help :-) I have gotten stuck in trying to use LINQ to read XML file in C#. This is the XML structure: <DataBase xsi:schemaLocation="http://somestuff.new/xml...
Jon Skeet
people
quotationmark

Your query expression is declaring a range variable called gaugeElement, but you're then using tpxElement within your code. I'd also use the conversions supplied by XElement to make your code simpler to read - and I wouldn't personally... more 1/18/2014 10:02:38 AM

people

What's the difference between these 2 ifs?

if(loadFactor != null && !(trialExists(loadFactor)) and if(!(loadFactor == null || trialExists(loadFactor)) I was asked in a review to make 1st if changed to 2nd....
Jon Skeet
people
quotationmark

There's no difference. In both cases: If loadFactor is null, trialExists(loadFactor) won't be evaluated, and the condition will be false, so it won't enter into the if body Otherwise, trialExists(loadFactor) will be evaluated, and the... more 1/18/2014 8:34:48 AM

people

ArrayList One loop sorted, the other unsorted

For this assignment I need to sort one list and also keep the original list, but when I click the button twice, the original list is also sorted. String output = ""; ...
Jon Skeet
people
quotationmark

I suspect you just want to take a copy of the list, then sort that: List<Song> sortedSongs = new ArrayList<Song>(song); Collections.sort(sortedSongs); // Will not affect song Note that this should be done before your loop,... more 1/17/2014 6:34:59 PM

people

How to convert decimal to money format

I'm trying to convert a number so it looks like the formatting in money. I need to take 258000 and make it 2,580.00 or 25000 and make it 250.00 or 360 and make it 3.60 This is...
Jon Skeet
people
quotationmark

It seems to me that you're just missing the fact that you can divide the user's input by 100 after parsing it: using System; class Program { static void Main(string[] args) { string input = "2500"; decimal cents =... more 1/17/2014 4:35:52 PM

people

Check the type of generic

I have a little problem with checking the type of a generic. Lets assume you have a list like this: public class List<T> { } In there you would like to check what type...
Jon Skeet
people
quotationmark

I suspect you're looking for Type.IsAssignableFrom: if (typeof(ICustomItem).IsAssignableFrom(typeof(T))) more 1/17/2014 3:35:02 PM

people

How to throw exception in static method, both in same class

Example1Exception and Example1Method belong together in the same file. It would not make sense to put them in separate files. public class Example1 { public class...
Jon Skeet
people
quotationmark

(Assuming you actually declare Example1Exception using a class declaration..., and that the method declaration is fixed too...) Example1Exception is an inner class - it needs a reference to an enclosing instance of the outer... more 1/17/2014 1:55:19 PM

people