Scroll to top

December 2018

C# Language : Iterators

Simple Numeric Iterator Example A common use-case for iterators is to perform some operation over a collection of numbers. The example below demonstrates how each…

Curious Bot December 1, 2018

C# Language : Hash Functions

MD5 Hash functions map binary strings of an arbitrary length to small binary strings of a fixed length. The MD5 algorithm is a widely used hash function producing…

Curious Bot December 1, 2018

C# Language : Reflection

Reflection is a C# language mechanism for accessing dynamic object properties on runtime. Typically, reflection is used to fetch the information about dynamic object…

Curious Bot December 1, 2018

C# Language : Task Parallel Library

Parallel.ForEach An example that uses Parallel.ForEach loop to ping a given array of website urls. static void Main() { string [] urls = { "www.stackoverflow.com",…

Curious Bot December 1, 2018

C# Language : Synchronization Context in Async-Await

Pseudocode for async/await keywords Consider a simple asynchronous method: async Task Foo() { Bar(); await Baz(); Qux(); } Simplifying, we can say that this code…

Curious Bot December 1, 2018

C# Language : Built-in Types

Immutable reference type – string // assign string from a string literal string s = "hello"; // assign string from an array of characters char[]…

Curious Bot December 1, 2018

C# Language : Networking

Basic TCP Communication Client This code example creates a TCP client, sends "Hello World" over the socket connection, and then writes the server response…

Curious Bot December 1, 2018

C# Language : Structural Design Patterns

Structural design patterns are patterns that describe how objects and classes can be combined and form a large structure and that ease design by identifying a simple…

Curious Bot December 1, 2018

C# Language : Implementing Flyweight Design Pattern

Implementing map in RPG game Flyweight is one of structural design patterns. It is used to decrease the amount of used memory by sharing as much data as possible…

Curious Bot December 1, 2018

C# Language : Recursion

Recursively describe an object structure Recursion is when a method calls itself. Preferably it will do so until a specific condition is met and then it will exit…

Curious Bot December 1, 2018

C# Language : Keywords

Keywords are predefined, reserved identifiers with special meaning to the compiler. They cannot be used as identifiers in your program without the @ prefix. For…

Curious Bot December 1, 2018

C# Language : Collection Initializers

Collection initializers Initialize a collection type with values: var stringList = new List<string> { "foo", "bar", }; Collection initializers…

Curious Bot December 1, 2018

C# Language : Initializing Properties

C# 6.0: Initialize an Auto-Implemented Property Create a property with getter and/or setter and initialize all in one line: public string Foobar { get; set; } =…

Curious Bot December 1, 2018

C# Language : Handling FormatException when converting string to other types

Converting string to integer There are various methods available for explicitly converting a string to an integer, such as: Convert.ToInt16(); Convert.ToInt32();…

Curious Bot December 1, 2018

C# Language : Timers

Multithreaded Timers System.Threading.Timer – Simplest multithreaded timer. Contains two methods and one constructor. Example: A timer calls the DataWrite…

Curious Bot December 1, 2018

C# Language : Reading and writing .zip files

Writing to a zip file To write a new .zip file: System.IO.Compression System.IO.Compression.FileSystem using (FileStream zipToOpen = new FileStream(@"C:\temp",…

Curious Bot December 1, 2018