
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialProgramming
4.5 Rating 114 Questions 60 mins read10 Readers

C#7.3 is the current version of C#. It is a multi-paradigm, generic and object-oriented programming languages. The following are the features:
Named arguments can be followed by positional arguments.
Easily reassign ref local variables in C# 7.3
Use initializers on stackalloc arrays.
Implement method dispatch on properties other than the object type.
A method’s out parameters can be defined directly in the method in C# 7.
You can define a function within the scope of another function. This gets local variables into the scope.
This includes deconstruction of tuples into separate variables and creating metadata for the names of tuple elements.
Discards are dummy variables intentionally unused in application code. The maintainability of the code and make its intent more clear.
These are beneficial in grouping digits in large numeric literals. These provide great readability and no significant downside.
These are literals in binary form. They are identical to hexadecimal literals except they use digits 0 and 1 with base 2. Binary literals are great for educational purposes and are low cost implementations.
The const in C# is faster than readonly, but the performance of const is not better than readonly.
A value with const keyword cannot change throughout the life of a program.
A const variable cannot be reassigned.
A value with Readonly keyword whose value can be initialized during runtime, unlike const.
Let us now see the difference:
| Basis | Const | Readonly |
|---|---|---|
| Local Variable | Can be applied to local variables. | Cannot be applied to local variables |
| Memory | Memory is not allocated. | Dynamic memory is allocated for readonly fields. |
| Static | Const are by-default static | To make it class member, include static keyword before readonly |
| Ref or out | We cannot pass const field as ref or out parameter | The readonly field can be passed as ref or out parameters in the constructor context. |
| Faster | Faster than readonly. | Readonly isn’t faster. |
| Performance | Performance isn’t better than readonly. | Performance is better than const. |
This is a frequently asked question in C# interview questions for freshers.
It is a suffix set in C# that is used while declaring float. This is used to inform the compiler the type of the literal. An example:
float a = 1239f;
An object of a class is a class instance in C#. All the members of the class can be accessed using the object or instance of the class.
The definition of the class instance starts with the class name that is followed by the name of the instance. Then the new operator is used to create the new instance.
A program that demonstrates a class instance in C# is given as follows:
using System;
namespace Demo
{
class Sum
{
private int x;
private int y;
public void value(int val1, int val2)
{
x = val1;
y = val2;
}
public int returnSum()
{
return x + y;
}
}
class Test
{
static void Main(string[] args)
{
Sum obj = new Sum();
obj.value(8, 5);
Console.WriteLine("The sum of 8 and 5 is: {0}" , obj.returnSum());
}
}
}The output of the above program is given as follows:
The sum of 8 and 5 is: 13
An array can be emptied using the Array.Clear() method. This method sets the required range of the elements in the array to their default values where the array type may be integer, boolean, class instances etc. To empty the whole array, the range of elements should simply be the length of the whole array.
A program that demonstrates the Array.Clear() method to empty the array is given as follows:
using System;
public class Demo
{
public static void Main()
{
int[] arr = new int[] {3, 9, 7, 1, 6};
Console.Write("The original integer array is: ");
foreach (int i in arr)
{
Console.Write(i + " ");
}
Array.Clear(arr, 0, arr.Length);
Console.Write("\nThe modified integer array is: ");
foreach (int i in arr)
{
Console.Write(i + " ");
}
}
}The output of the above program is given as follows:
The original integer array is: 3 9 7 1 6 The modified integer array is: 0 0 0 0 0
Creating a tuple with string and int items:
Tuple<int, string> t = new Tuple<int, string>(100, "john");
The following is an example:
using System;
class Example
{
static void Main()
{
Tuple<int, string> t = new Tuple<int, string>(100, "john");
if (t.Item1 == 100)
{
Console.WriteLine(t.Item1);
}
if (t.Item2 == "john")
{
Console.WriteLine(t.Item2);
}
}
}The output:
100 John
Managed Code is managed by the CLR. The managed code compiles into machine code. Applications under the control of CLR is managed code.
The code outside the .NET Framework is called unmanaged code. Wrapper classes are used to execute the unmanaged code. Applications not under the control of CLR is managed code.
The unmanaged code is the unsafe code that use a pointer variable.
Before passing a ref parameter, you must assign it to a value. However, before passing an out parameter, you don't need to assign it to a value.
A reference to a memory location of a variable. declare the reference parameters using the ref keyword. A ref parameter is passed as a reference, not a value.
With the out parameter, you can return two values from a function.
The following is an example of ref parameter:
using System;
class Example
{
static void Main()
{
string str1 = "one";
string str2 = "two";
string str3 = "three";
Display(ref str1);
Display(ref str2);
Display(ref str3);
Console.WriteLine(str1);
Console.WriteLine(str2);
Console.WriteLine(str3);
}
static void Display(ref string a)
{
if (a == "two")
{
a = null;
}
if (a == "three")
{
a = null;
}
}
}The output:
one
The following is an example of out parameter:
using System;
class Example
{
static bool Demo(out int a)
{
a = 5;
return a >= 5;
}
static void Main()
{
if (Demo(out int a))
{
Console.WriteLine(a);
}
}
}The output would be visible correctly on .NET 4.7 and above:
5
A common question in C# basic interview questions and answers, don't miss this one.
Yes, we can display all the files in a specific directory in C#. We have to use the DirectoryInfo class. Within that, set the directory from where you want to fetch all the files:
DirectoryInfo d = new DirectoryInfo(@"D:\sid");
The GetFiles() method is then used to get all the files in an array:
FileInfo [] fileInfo = d.GetFiles();
foreach (FileInfo f in fileInfo) {
Console.WriteLine("File Name: ", f.Name);
}The following is an example:
using System;
using System.IO;
namespace Application {
class Example {
static void Main(string[] args) {
DirectoryInfo d = new DirectoryInfo(@"D:\sid");
FileInfo [] fileInfo = d.GetFiles();
foreach (FileInfo f in fileInfo) {
Console.WriteLine("File Name: ", f.Name);
}
Console.ReadKey();
}
}
}The output displays the files in the “sid” directory:
NewOne NewTwo NewThree NewFour
To set 5-item tuple in C#, set it like this:
var t = new Tuple<string, string[], int, int, int>("laptop",
new string[] { "memoy card", "pen drive" },
30,
40,
50);Above, the tuple has string, string array, and three integer tuples. Therefore, making it a 5-item tuple.
The following is an example:
using System;
class Example {
static void Main() {
var t = new Tuple<string, string[], int, int, int>("laptop",
new string[] { "memoy card", "pen drive" },
30,
40,
50);
Console.WriteLine("Tuple Item 1 = "+t.Item1);
Console.WriteLine("Tuple Item 4 = "+t.Item4);
Console.WriteLine("Tuple Item 5 = "+t.Item5);
}
}The output:
Tuple Item 1 = laptop Tuple Item 4 = 40 Tuple Item 5 = 50
The System.OutOfMemoryException occurs when enough memory is not allocated.
Let us see an example:
using System;
using System.Text;
namespace Application {
class Example {
static void Main(string[] args) {
try {
string deptname = "Tom";
string loc = "North";
StringBuilder s = new StringBuilder(deptname.Length, deptname.Length);
s.Append(deptname);
s.Insert(value: loc, index: deptname.Length - 1, count: 1);
} catch (System.OutOfMemoryException e) {
Console.WriteLine("The following is the error:");
Console.WriteLine(e);
}
}
}
}The example displays the Out Of Memory Exception:
The following is the error: System.OutOfMemoryException: Out of memory at System.Text.StringBuilder.Insert (System.Int32 index, System.String value, System.Int32 count) [0x00065] in <902ab9e386384bec9c07fa19aa938869>:0 at Application.Example.Main (System.String[] args) [0x0002f] in <98ee8a52b3134b0799d382272292200f>:0
The SequenceEqual() method is used in C# to check whether two sequences are equal or not.
The following is an example:
using System;
using System.Linq;
class Example
{
static void Main()
{
string[] arr1 = { "one", "two", "three" };
string[] arr2 = { "one", "four", "five" };
bool res = arr1.SequenceEqual(arr2);
Console.WriteLine(res);
}
}The output:
False
Let us see another example:
using System;
using System.Linq;
class Example
{
static void Main()
{
string[] arr1 = { "HTML", "CSS", "JavaScript" };
string[] arr2 = { "HTML", "CSS", "JavaScript" };
bool res = arr1.SequenceEqual(arr2);
Console.WriteLine(res);
}
}The output:
True
Unsurprisingly, this one often pops up in C# interview questions for experienced professionals.
The Main Thread is the first thread that is created and executed inside a process. It is automatically created when the process starts execution.
A program that demonstrates the Main thread is given as follows:
using System;
using System.Threading;
namespace MultithreadingDemo
{
class Example
{
static void Main(string[] args)
{
Thread myThread = Thread.CurrentThread;
myThread.Name = "Main_Thread";
Console.WriteLine("This thread is the {0}", myThread.Name);
}
}
}The output of the above program is as follows:
This thread is the Main_Thread
Now let us understand the above program.
The CurrentThread property of the Thread class is used to access the Main thread. The name of the thread is specified is Main_Thread. After that, this is displayed. The code snippet for this is given as follows:
Thread myThread = Thread.CurrentThread;
myThread.Name = "Main_Thread";
Console.WriteLine("This thread is the {0}", myThread.Name);The Array.SyncRoot property gets an object used to synchronize access to the Array. Use the SyncRoot property to implement their own synchronization. This usage is for classes having arrays.
A default constructor takes no arguments. Each object of the class is initialized with the default values that are specified in the default constructor. Therefore, it is not possible to initialize the different objects with different values.
An example that demonstrates a default constructor is given as follows:
using System;
namespace DefaultConstructorDemo
{
class Sum
{
private int x;
private int y;
public Sum()
{
x = 5;
y = 7;
}
public int getSum()
{
return x + y;
}
}
class Test
{
static void Main(string[] args)
{
Sum s = new Sum();
Console.WriteLine("Sum: {0}" , s.getSum());
}
}
}The output of the above program is as follows:
Sum: 12
Now let us understand the above program.
First, the class Sum is initialized. It contains two private variables x and y. The default constructor Sum() initializes x and y to 5 and 7 respectively. Then the function getSum() returns the sum of x and y. The code snippet for this is given below:
class Sum
{
private int x;
private int y;
public Sum()
{
x = 5;
y = 7;
}
public int getSum()
{
return x + y;
}
}The main() function is in the class Test. It initializes an object s of class Sum. Then the sum of 5 and 7 is displayed using getSum(). The code snippet for this is given below:
class Test
{
static void Main(string[] args)
{
Sum s = new Sum();
Console.WriteLine("Sum: {0}" , s.getSum());
}
}