/* CSC 123 C# Warm up assignment Due one week from date assigned Part I: 1. C# is basically like Java, but there are some unique features. One of these is the "delegate" construct, which allows you to write higher-order functions. That is, functions that take other functions as arguments (such as map, fold, howmany, etc ...). Study the three sample programs on the homepage that uses delegates to understand how it works. Then write the delegate public delegate bool boolFun(int x); ( alternatively, with C# 2010, you can use Func ) And implement your favorite scheme/perl function "howmany" on arrays. That is, it should return the number of elements in an arrays of integers (see delegates.cs) for which the delegate function returns true. Demonstrate your program with at least two instantiations of the the delegate template. 2. The .Net API contains a built-in class called ArrayList, which works like the array/list structures in Perl. Go to the MSDN website and search for "ArrayList" for the complete docs, but the following example should be more than enough. The structure can be used like a list or an array. As the example indicates, you can store data of different types in the same ArrayList. That's because both strings and integers are implicitly type-cast to the ultimate supertype "object". As far as the compiler is concerned, each element of the ArrayList is an object. You cannot say A[3]+2 even if you know that A[3] is an integer - because all the compiler knows is that it's an object. Before you can use the element as an integer, you must explicitly type-cast it back to an int. Study the small program to make sure you understand this point. Remove the type-cast (int) operator in the program and observe what happens. Does it even compile? What if you try to use A[1] ("world") as an integer? That is, what if you try to add 2 to A[1] by first casting it to an integer? What kind of error do you get (compile time or runtime?) Record the behavior and EXPLAIN WHY. **You need to adopt the "howmany" higher-order function to work with ArrayLists instead of simple arrays. Remember to type-cast before you use the elements as integers.