C# compiler error: “not all code paths return a value”

You’re missing a return statement. When the compiler looks at your code, it’s sees a third path (the else you didn’t code for) that could occur but doesn’t return a value. Hence not all code paths return a value. For my suggested fix, I put a return after your loop ends. The other obvious spot – adding an else that had a return value to the if-else-if – … Read more

Adding values to a C# array

You can do this way – Alternatively, you can use Lists – the advantage with lists being, you don’t need to know the array size when instantiating the list.

failed to load resource: the server response with a status 500 (internal server error)

If your _service.getCardList() returns null then the foreach will throw an exception which you have not handled. Maybe that is the reason you are getting (500) internal server error and not the jquery url, as 500 error code suggests that something went wrong in the server code. As a suggestion, You should use implement try – catch and log the exceptions somewhere to be able to … Read more

What is the difference between int, Int16, Int32 and Int64?

Each type of integer has a different range of storage capacity As stated by James Sutherland in his answer: int and Int32 are indeed synonymous; int will be a little more familiar looking, Int32 makes the 32-bitness more explicit to those reading your code. I would be inclined to use int where I just need ‘an integer’, Int32 where the size is important (cryptographic code, … Read more

Priority queue in .Net

You might like IntervalHeap from the C5 Generic Collection Library. To quote the user guide Class IntervalHeap<T> implements interface IPriorityQueue<T> using an interval heap stored as an array of pairs. The FindMin and FindMax operations, and the indexer’s get-accessor, take time O(1). The DeleteMin, DeleteMax, Add and Update operations, and the indexer’s set-accessor, take time O(log n). In contrast to an ordinary priority queue, an interval heap … Read more

LINQ’s Distinct() on a particular property

EDIT: This is now part of MoreLINQ. What you need is a “distinct-by” effectively. I don’t believe it’s part of LINQ as it stands, although it’s fairly easy to write: So to find the distinct values using just the Id property, you could use: And to use multiple properties, you can use anonymous types, which implement equality appropriately: … Read more

Unity OnTriggerEnter2D not registering

There are four things I can think of which need to happen so that OnTriggerEnter gets called: The two objects’ colliders need to actually be overlapping. Just because their rendered pixels are overlapping, doesn’t mean their colliders are overlapping. This can be checked in the editor. Their colliders are indicated with a green outline in the Scene tab. If … Read more