Wednesday, June 15, 2011

LINQ interview questions

In this post we will review a bunch of small and simple LINQ interview questions to get you started. Once you understand these standard query expressions, it should be a breeze for you to answer LINQ questions.

Question: Given an array of numbers, find if ALL numbers are a multiple of a provided number. For example, all of the following numbers - 30, 27, 15, 90, 99, 42, 75 are multiples of 3.

The trick here is to use the Enumerable.All<TSource> method which determines whether all elements of a sequence satisfy a condition.

publicstaticvoid ActiveGpsManufacturers() {// Determine which manufacturers have a active device. IEnumerable<string> activeManf = from manf in gpsManufacturers // for all manufacturerswhere manf.Devices != null && // they have a list of devices// and at least one of the device is active manf.Devices.Any(m => m.IsActive == true) select manf.Name; // select them

// just for debuggingforeach (string name in activeManf) Console.WriteLine(name); }

As an extension question and using Lambda expressions, consider the following question:

Question: Find the count of all the manufacturers that have at least 1 or more active GPS devices.

14 comments:

Hip Hip Hooray! I was always told that slightly slow in the head, a slow learner. Not anymore! It’s like you have my back. I can’t tell you how much I’ve learnt here and how easily! Thank you for blessing me with this effortlessly ingestible digestible content.Do you know something about that? is it coming? is going to progress? A friend of mine told me but I didn't understand very well.There can be many reasons due to which application can be taking too long, however one reason can be wrong configuration of Xms. For instance, if Xms value is too high, close to physical memory (RAM) than pagination of memory will start happening, resulting in slowness of application. if you know something about this, can you share with me?THANK YOU!! This saved my butt today, I’m immensely grateful.

Amaze! I have been looking bing for hours because of this and i also in the end think it is in this article! Maybe I recommend you something helps me all the time?

have created a Cache connection manager to store 20GB of data. My Physical memory on the server is 1.5TB and whey I run the package, it is failed at Cache connection with the following error.Deactivate rollback segment R0 and activate the newly created rollback segments.Error: The system reports 12 percent memory load. There are 1649153396736 bytes of physical memory with 1446557532160 bytes free. There are 4294836224 bytes of virtual memory with 39915520 bytes free. The paging file has 1711430443008 bytes with 1493163847680 bytes free.Error: A buffer failed while allocating 14679520 bytes.When it caches data, where is it stored? Physical Memory or Virtual Memory??How to change it to store in Physical Memory?