CSharp

From eqqon

Jump to: navigation, search

C# Articles

32px-CSharp.jpg
 
Author: User:Henon
GitSharp  -  Git#
Git# is a pure C# implementation of Git that does not depend on Cygwin or any other compatibility layers   Read GitSharp ...
32px-CSharp.jpg
 
Author: User:Henon
Double Dispatch Mechanism  -  the Visitor Pattern
Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution.   Read Double Dispatch Mechanism ...
32px-CSharp.jpg
 
Author: User:Henon
An event is just an accessor (+=, -=) to a field holding a MulticastDelegate. The difference between a publicly accessible delegate field and an event are that you cannot overwrite the existing registered delegates, only append or remove. You also cannot reset the private event handler field to null from outside.   Read Events ...
32px-CSharp.jpg
 
Objects that implement IDisposable can be used in the using statement. After the block ends, the object's Dispose-method is guaranteed to be called. Note: The object's destructor is not guaranteed to be called immediately.   Read IDisposable ...
32px-CSharp.jpg
 
Author: User:Henon
Today I wrote a nice little debug helper function called PrintException. It prints the relevant informations about an exception and its inner exceptions to the output recursively. The clue is, that it does this in a format that is understood by the error parser of Microsoft Visual Studio. So if you get an exception you can easily navigate to the source locations by clicking on the lines in the printed stacktrace. It also prints inner exceptions recursively with increasing indent for better readability.   Read Navigating in Exception Stack Traces in Visual C-Sharp ...
32px-CSharp.jpg
 
Events that cause each other to be fired recursively are usually a problem when two classes need to sync data. In large programs these recursive call chains can be quite long and thus a recursion might not be expected when firing some event. The recursion ends in a StackOverflowException. There are many possibilities to resolve such a problem. The easiest one is to introduce a boolean locking field which prevents reentrancy.   Read Preventing Recursive Events ...
32px-CSharp.jpg
 
Author: User:Henon
Although I am very impressed by C#, Ruby is still my favorite programming language because of it's clean design and unreached flexibility. One of the things I like about Ruby is its way to mark instance variables (in Ruby's terminology) or member variables / fields (in C# terminology). They are prefixed with the @-sign. This makes code very easy to read. To get the same effect most C# programmers rely on a kind of Hungarian style notation which means prefixing with m_. Today I discovered that the C# compiler allows the @-sign as prefix for identifiers. This is useful if you need to name an identifier e.g. a variable like a keyword. How often have I been forced to unwillingly name variables which contain a class-object klass or _class when programming in Ruby. So this is really a nice feature of C#, isn't it?   Read Ruby-like instance variable syntax in C-Sharp ...
32px-CSharp.jpg
 
SQLite and CSharp  -  integrate SQlite with C#
The easiest way for an application to set up a database back-end is SQLite. Here is a small sample that creates a table, inserts some data and queries them back in C#. We use LiteX which is a nice .Net wrapper for SQLite 3.   Read SQLite and CSharp ...
32px-CSharp.jpg
 
Author: User:Henon
To let one thread send data to other threads without interfering with them we combined a Queue with an AutoResetEvent in our Stream class. The stream maintains it's own receiver thread which sleeps (without polling) until some token is available. Then the OnReceive event is fired which executes the processing routines without delaying the sender. This decouples the sender and the receiver's execution contexts from each other which is needed for realtime applications. For optimal efficiency the generic Queue<T> has been chosen to avoid a lot of boxing and unboxing operations.   Read Streaming between Threads or Processes ...
32px-CSharp.jpg
 
Author: User:Henon
Using (special use in C-Sharp)  -  the using keyword
Apart from including namespaces in C# the keyword using is also overloaded with another meaning related to IDisposable.   Read Using (special use in C-Sharp) ...
32px-CSharp.jpg
 
Author: User:Henon
Imagine you have a big class hierarchy and you are writing a sophisticated class that does something different for each type in the hierarchy. You cannot put the functionality into the respective classes for some reason. Here is a very simplified code example which demonstrates the situation and implements a naive solution.   Read Visitor Pattern ...
32px-CSharp.jpg
 
Author: User:Henon
Ever found yourself writing a custom collection in C# just to be able to pass an IEnumerator into a method that expects IEnumerable? Writing such boilerplate code is never a good idea. The classes Iterator and Iterator<T> presented in this article fill in the missing link from IEnumerator to IEnumerable allowing you to be more productive with iterators.   Read Closing the Gap Between IEnumerator and IEnumerable ...

Category:CSharp


External C# Links

Tutorials and Articles
Libraries
Tools
2.0