Visual C# Tutorials

Generate Complex XML with Multiple Namespace Prefixes from SQL Server Database

Generate Complex XML with Multiple Namespace Prefixes from SQL Server Database

XML is very versatile and still the most commonly used data format in most applications we developed today. The .NET Framework provides several namespaces and classes that allow developers to read, write and interact with the XML documents. Many developers over the last few months have requested me to write a tutorial on generating XML documents from the data stored in SQL Server database so I thought to write something on this topic. In this tutorial, I will demonstrate how we can load data from SQL Server database and generate complex XML documents programmatically using the classes and XML related attributes available in .NET Framework. I will also explain how we can create XML elements with multiple namespace prefixes.

Overview of C# 3.0 Anonymous Types

Microsoft introduced some great new features in C# 3.0 to make developers more productive. Most of those features are introduced to support Language Integrated Query (LINQ) but they can also be used in many other scenarios. One such feature is Anonymous Types that allows you to define a class with some simple encapsulated fields without any associated methods, events or functionality. In this tutorial I will give you overview of C# 3.0 Anonymous Types.


Overview of C# 3.0 Object Initializers

When you create object of any type in C#, it is very common to call its default constructor using new keyword and then set the object properties one by one. The new object initializer syntax introduced in C# 3.0 makes it easier for us to initialize our objects in one statement without calling the object parameterize constructor. In this tutorial I will give you an overview of this new Object Initializer feature of C# 3.0.

Understanding C# 3.0 Extension Methods

Understanding C# 3.0 Extension Methods

As you know, once a type such as class, interface, and structure is defined and compiled into a .NET assembly, it is not possible to add new members or update existing members without opening and changing the source code and recompiling it again. In C# 3.0, Microsoft introduced a new feature called Extension Methods that enable developers to add new functionality to existing precompiled types. These types can be either .NET Framework built in types such as String and DateTime or they can be your custom types. In this tutorial I will try to give you a complete overview of extension methods.

Overview of C# 3.0 Automatic Properties

All .NET programming languages prefer the use of Properties to encapsulate the private fields available in the class. There is nothing too problematic with Properties but sometimes when you need properties simply to assign and return the value stored in a private field it looks quite a lot of work especially if you have to declare properties for 15 to 20 private fields. To automate the process of providing simple encapsulation of field data C# now has a new syntax to generate automatic properties. In this tutorial I will show you how you can create Automatic Properties and how you can use them in your programs.

Implicitly Typed Local Variables in C# 3.0

Microsoft introduced quite a number of new features in C# 3.0 and later version and most of them are added in the language to support another new technology LINQ. One of those features is implicitly typed variables that allow you to create a local variable by using a newly added var keyword without giving it a specific type. In this tutorial I will give you introduction of implicitly typed variables and their use in your programs.

Singleton Design Patten in C#

The singleton pattern is one of the most known and easiest design patterns in software engineering. In simple words, a singleton is a class which only allows a single instance of itself to be created. There are various different ways to implement this pattern in C#. In this tutorial, I will show you how you can implement the singleton design pattern with minimum amount of code.

Using XmlTextWriter to write XML Documents in .NET

Using XmlTextWriter to write XML Documents in .NET

XML is one of the most popular topics these days. As the use of XML files is increasing, more and more developers want to learn how to write, read and consume XML documents from different programming languages. In the following tutorial, I will show you how you can use .NET Framework built in class XmlTextWriter to generate XML document in C#.

Using C# Delegates with Events

Using C# Delegates with Events

.NET Delegates are objects which can refer to static and instance methods in memory at runtime and can call those methods in your program. In this tutorial I will show you how you can create and use delegates in C#.

Storing Database Connection Strings in App.Config

Storing database connection strings in source code can lead you to some security issues and can also cause you maintenance problems. It is always recommended that you keep your connection strings in a separate configuration file so that you can change database connection related information such as password or database name without even modifying or recompiling your source code.