C#
Top 50 C# Interview Questions and Answers for 2021
C# is a general purpose programming language which encompasses various disciplines like...
The C# language comes with a set of Basic data types. These data types are used to build values which are used within an application. Let's explore the basic data types available in C#. For each example, we will modify just the main function in our Program.cs file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
class Program
{
static void Main(string[] args)
{
Int32 num=30;
Console.Write(num);
Console.ReadKey();
}
}
}If the above code is entered properly and the program is executed successfully, following output will be displayed.
From the output, you can clearly see that the Integer variable called num was displayed in the console
A double data type is used to work with decimals. In this case, the numbers are whole numbers like 10.11, 20.22 or 30.33. In C#, the datatype is denoted by the keyword "Double". Below is an example of this datatype.
In our example, we will define a double variable called num. We will then assign a Double value to the variable and then display it accordingly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
class Program
{
static void Main(string[] args)
{
double num=30.33;
Console.Write(num);
Console.ReadKey();
}
}
}If the above code is entered properly and the program is executed successfully, following output will be displayed.
From the output, you can clearly see that the double variable called num was displayed in the console
A boolean data type is used to work with Boolean values of true and false. In C#, the datatype is denoted by the Boolean keyword. Below is an example of this datatype can be used.
In our example, we will define a Boolean variable called 'status.' We will then assign a boolean value to the variable and then display it accordingly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
class Program
{
static void Main(string[] args)
{
Boolean status=true;
Console.Write(status);
Console.ReadKey();
}
}
}If the above code is entered properly and the program is executed successfully, the output will be displayed.
From the output, you can clearly see that the Boolean variable which equals true was displayed in the console
A String data type is used to work with String values. In C#, the datatype is denoted by the keyword 'String'. Below is an example of this datatype.
In our example, we will define a String variable called 'message.' We will then assign a String value to the variable and then display it accordingly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
class program
{
static void Main(string[] args)
{
String message="Hello";
Console.Write(message);
Console.ReadKey();
}
}
}If the above code is entered properly and the program is executed successfully, the output will be displayed.
From the output, you can clearly see that the String variable called message was displayed in the console
C# is a general purpose programming language which encompasses various disciplines like...
What is ArrayList in C#? The ArrayList collection is similar to the Arrays data type in C#. The...
Accessing Data from a database is one of the important aspects of any programming language. It is...
What is Hashtable in C#? A hash table is a special collection that is used to store key-value...
C# is based on the C++ programming language. Hence, the C# programming language has in-built...
In this tutorial, you will learn- Inheritance Polymorphism What is Inheritance in C#? Inheritance is...