Scroll to top

Blog

C# Language : Hash Functions

MD5Hash 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 : Iterators

Simple Numeric Iterator ExampleA 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 : Task Parallel Library

Parallel.ForEachAn example that uses Parallel.ForEach loop to ping a given array of website urls. static void Main() { string [] urls = { "www.stackoverflow.com", "www.google.net", "www.facebook.com", "www.twitter.com" }; System.Threading.Tasks.Parallel.ForEach(urls,…

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 : Synchronization Context in Async-Await

Pseudocode for async/await keywordsConsider 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 { 'h', 'e',…

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 : Networking

Basic TCP Communication ClientThis 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 : 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 : Recursion

Recursively describe an object structureRecursion 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 : Implementing Flyweight Design Pattern

Implementing map in RPG gameFlyweight 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 : Handling FormatException when converting string to other types

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

Curious Bot December 1, 2018

C# Language : Initializing Properties

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

Curious Bot December 1, 2018

C# Language : Collection Initializers

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

Curious Bot December 1, 2018

C# Language : Timers

Multithreaded TimersSystem.Threading.Timer - Simplest multithreaded timer. Contains two methods and one constructor. Example: A timer calls the DataWrite method,…

Curious Bot December 1, 2018

C# Language : Reading and writing .zip files

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

Curious Bot December 1, 2018

C# Language : IEnumerable

IEnumerable is the base interface for all non-generic collections like ArrayList that can be enumerated. IEnumerator<T> is the base interface for all generic…

Curious Bot December 1, 2018

C# Language : LINQ Queries

LINQ is an acronym which stands for Language INtegrated Query. It is a concept which integrates a query language by offering a consistent model for working with…

Curious Bot December 1, 2018

C# Language : Enum

An enum can derive from any of the following types: byte, sbyte, short, ushort, int, uint, long, ulong. The default is int, and can be changed by specifying the…

Curious Bot December 1, 2018

C# Language : IComparable

Sort versions Class: public class Version : IComparable<Version> { public int[] Parts { get; } public Version(string value) { if (value == null) throw new…

Curious Bot December 1, 2018

C# Language : CLSCompliantAttribute

Access Modifier to which CLS rules applyusing System; namespace CLSDoc { public class Cat { internal UInt16 _age = 0; private UInt16 _daysTillVacination = 0; //Warning…

Curious Bot December 1, 2018

C# Language : Getting started with C# Language

Creating a new console application (Visual Studio) Open Visual Studio In the toolbar, go to File ? New Project Select the Console Application project type Open the…

Curious Bot December 1, 2018

C# Language : Looping

Looping stylesWhile The most trivial loop type. Only drawback is there is no intrinsic clue to know where you are in the loop. /// loop while the condition satisfies while(condition) { ///…

Curious Bot December 1, 2018

C# Language : Dependency Injection

Dependency Injection C# and ASP.NET with UnityFirst why we should use depedency injection in our code ? We want to decouple other components from other classes in…

Curious Bot December 1, 2018
Loading