Academic year 2013/2014, Summer semester
Programming Windows in .NET (eng.)
Lecture - tuesdays at 8.30 classroom no.5.
Labs - tuesdays at 10.15 (with Łukasz Piwowar)
Excercise sets
Excercise Set 1. Due date: March, 25th
Excercise 1.
Install any version of Visual Studio 2013 on your personal computer (in case of the Express Edition, make sure
you install the Windows Desktop edition).
Excercise 2.
Use the Visual Studio to compile and then execute first three example codes from the Win32API example set
presented at the lecture (available here).
Excercise 3.
Learn to debug the code - show how breakpoints can be set in the source, what happens when the execution
hits your breakpoints, how to inspect the state of variables when an exception is hit and how to resume the execution.
Excercise Set 2. Due date: April, 1st
Excercise 1.
Write a C# application that finds a largest 3-digit number that can be divided by each one of its its digits.
Excercise 2.
Decompile the program from the previous task using ildasm.exe
Excercise 3.
Recompile the CIL source with ilasm.exe
Excercise 4.
Decompile the program with a high-level decompiler (IlSpy) and save it as a project so that
you can use VS to recompile it
Excercise Set 3. Due date: April, 15th
Excercise 1. (indexers)
Implement a two-dimentional grid class with two indexers
- a one-dimentional indexer that returns a list of elements of given row of the grid so that the client could call it like
...
Grid grid = new Grid( 4, 4 );
int[] rowdata = grid[1]; // "get" accessor
- a two-dimentional indexer that returns a given element of the grid so that the client could call it like
...
Grid grid = new Grid( 4, 4 );
elem[2, 2] = 5; // "set" accessor
int elem = grid[1, 4]; // "get" accessor
Both indexers should take integer numbers as parameters. The class constructor should take the number of rows and columns
as parameters.
Excercise 2. (reflection)
Write a program that demonstrates the ability to access private members from outside of the class.
The code should contain an example class with at least one private method and one private property. The client code should be able
to access both private members via reflection.
Also, write code that compares the time spent on accessing members directly with the time spent on accessing members via reflection.
How much slower the reflection is?
Hint. To measure time, use following block
DateTime Start = DateTime.Now;
/* code block here */
DateTime End = DateTime.Now;
TimeSpan Czas = Start-End;
Console.WriteLine( Czas );
Remember to repeat the code block enough times to get a meaningfull results.
Excercise 3 (attributes)
Write a method that takes any object as a parameter and finds all its public, instance methods with empty parameter list and integer return value.
Then, all methods that are marked with [Marked] attribute are executed.
public class Foo
{
[Marked]
public int Bar()
{
return 1;
}
public int Qux()
{
return 2;
}
}
Excercise set 4. Due date May, 13th, 2014
Excercise 1. (LINQ to Objects, sorting, filtering)
There is a text file which contains natural numbers in consecutive lines.
Write a LINQ expression, which reads all numbers and prints out only these numbers
which are less than 100, all of them in a descending order.
from number in [expression_which_reads_numbers_from_file]
where ...
orderby ...
select ...
Reformulate the LINQ expression into a chain of LINQ method calls:
[expression_which_reads_numbers_from_file].Where( ... ).OrderBy( ... )
Excercise 2. (LINQ to Objects, grouping)
There is a text file which contans persons names in consecutive lines.
Write a LINQ expression which returns a set of all first letters of these names in an
alphabetical order. For example, for the file
Kowalski
Malinowski
Krasicki
Abacki
the result should be
A, K, M
Excercise 3. (LINQ to Objects, analyzing server logs)
The event log of an application server is a text file of the form:
08:56:36 214.54.15.1 POST /AnotherApplication/test.jpg 200
08:55:36 192.168.0.1 GET /TheApplication/WebResource.axd 200
....
The first column is a datetime, then there’s the client’s IP number, HTTP request type,
resource name and the response status.
Write one (or more) LINQ expression which will show IP numbers of the top three clients
who sent the highest number of requests.
An example result should look like:
12.34.56.78 143
23.45.67.89 113
123.245.167.289 89
where the first column is the client’s IP number and the second column is the total number
of requests.
Excercise set 5. Due date June, 03th, 2014
Excercise 1. (Windows.Forms, user interface)
Write a simple Windows.Forms application that presents a list of students.
List of requirements:
- The list is read and written from a text file
- There are separate classes for student data and the address and there is an association between the two (each student has an address)
- There is a separate class to represent the whole model of data (the list of students), the model class is where operations on the list
(reading, writing) are implemented
- The main form of the application has a menu that allows users to open an existing file, create new file or save currently used data
- When the file is selected, the main form shows a list/grid of students from the file, including their name, given name, age and address
- Double clicking an item on the list/grid opens a new child modal form that allows user to modify selected item
- Somewhere beside the list/grid there is a button that allows user to create a new student data (the very same window can be opened that is used
to modify data)
Lectures
- 2014.02.25
- 2014.03.04
- Visual Studio
- Win32 Application Programming Interface
- Win32 messaging infrastructure
- Basic Win32 functions
- 2014.03.11
- Window hierarchies (parent windows vs child windows)
- Communication in a window hierarchy
- Native shared libraries (*.dlls)
- Basic Win32 functions
- 2014.03.18
- .NET - philosophy, history
- Common Intermediate Language (CIL)
- Decompilation
- 2014.03.25
- Mixing different programming languages in the same solution
- C# - fundamentals of the type system
- C# - classes, fields, methods, constructors
- C# - polymorphism, overloading
- 2014.04.01
- C# - Properties, indexers
- C# - Delegates, events
- 2014.04.08
- C# - Reflection, attributes
- 2014.04.15
- C# - yield (continuations)
- C# - generics
- 2014.04.29
- C# - Linq2Objects
- C# - Linq2SQL
- 2014.05.06
- C# - dynamics
- .NET Base Class Library - introduction to Windows.Forms
- 2014.05.13
- Windows.Forms - managing layouts
- Windows.Forms - component overview (buttons, textboxes, combos, lists, grids)
- 2014.05.20
- Software engineering - discussion
- 2014.05.27
- lecture cancelled - class absent
- 2014.06.03
- introduction to web programming
- 2014.06.10
- asp.net webforms vs asp.net mvc
Bibliography
- Charles Petzold, Programming Windows 5th Edition
- Bruce Eckel, Thinking in C#
- Andrew Troelsen, Pro C# and the .NET Platform 4.5
- Daniel Solis, Illustrated C#