You know the feeling when you see someone use a property and you go, nice, I never knew that. Well last night that happened to me after reading Scott Hanselman’s article on Windows Powershell. In the article he created a script that automatically downloaded his podcasts. To do this he use the System.Uri class which has a property called Segments. Segments returns a string array which consists of elements in a Uri separated by a forward slash ‘/’. So lets say you have this url: http://developer.yahoo.com/yap/guide/caja-support.html You could then use System.Uri to get all the bits in the Uri like this: Uri url = ...
Read Full Story
One of the objectives of Exam 70-536 is Implementing interoperability, reflection, and mailing functionality in a .NET Framework application Call unmanaged DLL functions within a .NET Framework application, and control the marshalling of data in a .NET Framework application. There are several subtopics in this requirement. The example presented today will cover Create a class to hold DLL functions; Create prototypes in managed code Call a DLL function Call a DLL function in special cases, such as passing structures and implementing callback functions Many interop examples seem to cover the simplistic case of hello world in a dialog. But the real challenge when calling ...
Read Full Story
C# uses a lot of streams, or at least it seems so in some of the code examples I have looked at. Having said that I felt the need to read up on the Stream class. The stream class is an abstract class and an abstract acts as a type of base class from which other classes can inherit. And just to recap, abstract methods do not have a method body and must be implemented by the class inheriting from it. A method marked as virtual can be overridden but it does not have to be implemented. Methods that are marked as abstract can ...
Read Full Story
I have been looking for a way to stream database results for a while now, and has as yet not come to a fitting solution. That is until today and after I did some reading on the yield keyword. The yield keyword can be used inside a function that implements the IEnumerable interface and what it seems to do is force a loop to return a result even though its not finished. Lets say for instance you have a function like this: public static IEnumerable Power(int number, int exponent) { int counter = 0; int result = 1; while (counter++ < exponent) { result ...
Read Full Story
On Monday I started working through some LINQ to XML and it got me so excited that I misunderstood some project requirements that ended up being quite wrong. It did not, however, diminish my enthusiasm. I ended up using a small part of the code in the end anyway, even though it was not in a production environment. Lets say you have a collection of XML documents and you would like to know what elements appear in all of them, so at the end of it all you have a single of list of elements that appear between all of them. This is how ...
Read Full Story