Generics in C# .NET With Examples

In this article, we are going to talk about the use of Generics in C# with examples.

What is Generic in C#

 Generic  in C# was introduced in.NET Framework 2.0, it is basically enhancement of collection which makes our code type independent so that we can reuse our code with different data types.

For example, List in C# is a generic collection that can be used with the different data type, such as List<int>, List<float>, List<string>, or List<Employee>

Generics in C# belongs to  System.Collections.Generic  namespace which contains several generic-based collection classes. Continue reading “Generics in C# .NET With Examples”

Properties In C# with examples

In this article, we are going to talk about the use of properties in C# with examples.

What are the Properties in C#

A Property in C# is an extension of a field that provides a public way for the classes to read, write, and expose the private fields while hiding the implementation details.

Properties in C# are actually a special kind of getter and setter methods wrapped around a private variable. A  get  property accessor is used to retrieve the value and the  set  accessor is used to assign the new value.

( get : Retrieve  set : Assign)                  

C# Properties
Properties in C#

Property Syntax in C#

Continue reading “Properties In C# with examples”

var keyword in C#-Restrictions and Advantage of using var variable

In this article, we will understand the var keyword in C#.

var keyword in C#

The  var  keyword was introduced in C# 3.0 to declare an implicitly typed of local variable to hold any type of data.
In implicitly typed variables, the type of the variable declared is decided by the compiler at the compile-time based on the type of the value that the variable is initialized with.
The variable declared as  var  is mandatory to initialize at the time of declaration.

var keyword in C#
var variable in C#

The following are the implicitly and explicitly typed variables declaration in C#.

Continue reading “var keyword in C#-Restrictions and Advantage of using var variable”

Primary Key Constraint In SQL Server

What is the primary key in SQL Server?

In SQL Server, a  Primary Key  is a field or column which uniquely identifies each and every record in a table.

    • A primary key column doesn’t allow to insert  null  or duplicate values.
    • A Primary key can consist of up to 16 columns.
    • A table can have only one primary key which can be applied on single or multiple columns.
    • The primary key consist of multiple columns or fields is known as the Composite primary key.
    • A Primary Key constraint can be applied to the columns having any data types.
    • A primary key by default creates a clustered index on the column.

A primary key can be created at the column or table level.

Primary Key Constraint  in SQL Server
Primary Key Constraint in SQL Server

Syntax to create a primary key

The following are the syntax to create a primary key in SQL server.

Continue reading “Primary Key Constraint In SQL Server”

Generic Delegates in C# With Examples

In the previous article, we have learned about the delegates and their types. Now in this article, we are going to discuss the generic delegates in C#.

What are the generic delegates?

The  Func ,  Action  and  Predicate  are the three generic delegates which were introduced in .NET 3.5 and are availables in System namespace.

We can make use of all these three predefined generic delegates when we want to invoke the methods without defining the delegates explicitly.

Func delegate in C#

Func generic delegates in c#

Func is a generic delegate that is available in the System namespace.

It can take up to 16 input parameters of the same or different data types and one out parameter.

Continue reading “Generic Delegates in C# With Examples”

Page 1 of 5
1 2 3 4 5