What is C# history?
C# (pronounced "C Sharp") is a programming language that is latest, flexible. It is made by Microsoft. C# is an object-oriented programming language that support four main pillar of OOP Abstraction, Encapsulation, Inheritance, Polymorphism. It run on .NET Framework. It's history start from late 1990s.
2. What are C# main feactures?
C#, which is also called C Sharp, is a programming language that was made by Anders Hjelsberg. C# combines the computational power of C++ and the ease of Visual Basic, Microsoft’s event-driven programming language and environment. C is the building block from which C# is made. Microsoft came out with C# in the year 2000. It was made to meet the growing demand for online applications that Visual Basic (VB) and C++ can’t meet. Because of this, so The programmers who know how to work with C and C++ can quickly learn how to use C# and by using C# you can make website and desktop application very easily in versatile way and you can also use web services that make capable two or more systems to exchange data over network. Data are exchanged either using XML or JSON.
Here, below are some main features of C#
1 - Object-Oriented
2 - Type Safety
3 - Garbage Collection
4 - Cross-Platform Development (C# 9.0 and later)
5 - Managed Code
6 - Rich Standard Library
3. What is Dot Net Framework?
Dot NET Framework is a software development framework for making and running applications on Windows. Dot Framework is part of the .NET platform and provide us a collection of technologies for building website, software and apps for Linux, macOS, Windows, iOS, Android. It has a common runtime (CLR - Common Language Runtime) and a large number of class library that supports more then 60 programming languages, including C#. .NET Framework is the original implementation of .NET. It supports running websites, services, desktop apps, and more on Windows.
4. What is Common Language Runtime (CLR)?
The management of the execution of.NET applications is the responsibility of the CLR. It provides a range of services including garbage collection, exception handling and security. It is a program execution engine that loads and executes the program. It converts the program into native code. It acts as an interface between the framework and operating system. It does exception handling, memory management, and garbage collection. Moreover, it provides security, type-safety, interoperability, and portablility. A list of CLR components are given below:
5. What is Base Class Library (BCL)?
The BCL contains a set of classes, interfaces and value types that provide the essential functionality for your.NET applications. It's about collections, files, networking, security, and more.
6.What are keywords in C#?
Keywords that we use in C# programming language have special meanings and these Keywords as they are special in programming so we cannot used it as identifiers specially like variable name, method name, and class names in you code.
We define vairable with string keyword in C#.
Here, in below example
string - a keyword
fruitName - variable name
// Define a string variable
string fruitName;
7. What are operators in C#?
In C#, operators are symbols or keywords used to perform various operations on data, such as arithmetic calculations, logical comparisons, and assignments.
8. What are data types in C#?
The behavior of storing data in variable are described with data types. It is responsibility of a specific data type to store a specific value. For example number values are store in integer type data types.
Primitive Data Types:
Integral Types:
Floating-Point Types:
Character Type:
Boolean Type:
Reference Data Types:
String Type:
9. What are Variables in C#?
Variables in C# are used for storing data this data can be in shape of number, characters, text and true, false and decimal. for example for example: int - stores integers (whole numbers), without decimals, such as 123 or -123. double - stores floating point numbers, with decimals, such as 19.99 or -19.99 and char store character like 'A' and string store text like "Apple Red!"
10. What is break statement in C#?
In C#, the break statement is a control flow statement that is used to exit a loop or switch statement prematurely. It allows you to terminate the execution of the innermost loop or switch block and continue with the code immediately following the loop or switch statement
11. What is continue statement in C#?
The continue statement is used to skip the current iteration of a loop. This continue statement usually we used with for, while, do-while statement. when continue statement skipped the current iteration then control goes to next iteration. It is typically used within loops to control the flow of execution based on a specific condition.
12. What is goto statement in C#?
In C#, the goto statement allows you to transfer control to a labeled statement within the same method or block of code.
13. What is function in C
In C#, a function is a block of code that performs a specific task and can be called from other parts of your program. Functions are a fundamental concept in C# and are often referred to as methods.
Functions in C# are known as methods and are defined within a class or struct. They can have parameters, which are variables passed into the method, and they can return a value or be void (returning no value).
14. What is ref parameter in C
In C#, the ref keyword is used to indicate that a method parameter is a reference parameter.
Reference parameters allow you to pass a reference to a variable as an argument to a method, rather than passing a copy of the variable's value. This means that any changes made to the parameter within the method will affect the original variable outside the method as well.
15. What is out parameter in C
The out keyword is used to declare output parameters in method or function signatures. The output parameter is a parameter that is used to return multiple values from a method. The output parameters are used to pass data out of a method. But a normal function is used for passing the data inside function.
16. What is in parameter in C
in is used to state that the parameter passed cannot be modified by the method. An any attempt to modified will give you compile-time error. in parameter was introduced in C# 7.2.
17. What is array in C
Array is such type of collection that have the capability to stores a fixed-sized elements of the same data type. But have the difference with mixed data types like array List that can store mixed data types.
In array you can store multiple values of the same data type for example you can store multiple values of int data type of same variable and similarly In array you can also access multiple values of the same type under a single variable name.
Suppose we need to record the 7 different numbers. Instead of creating 7 separate variables, we can simply create an array:
18.Can we pass array to function?
A function can receive a parameter. Similarly a function can also receive an array. We can pass an array as parameter to function. In this activity, when we pass an array to a function we actually passes a reference to the array. we give permission to a function that it can access and can modify the elements of the array.
19.What is multidimensional array in C#?
If you have date in the shape of tables, matrices, grids then multidimensional arrays are useful. We declared the multidimensional array by adding commas in the square brackets. We can declare two-dimensional, three-dimensional, four-dimensional array in such a way respectively [,], [, ,], [, , ,].
20. What is jagged array in C#?
In C#, a jagged array is an array of arrays. Unlike rectangular (multidimensional) arrays, jagged arrays allow each element of the outer array to be an array of different lengths. This flexibility makes jagged arrays useful for representing irregular data structures where the inner arrays can have varying sizes. Each row (dimension) has a different length or size in jagged arrays, but in a multidimensional array, each row (dimension) has fixed or the same length because because each row is essentially a separate array.
21. What are params in C#?
In C#, "params" is a keyword used in method parameter to indicate that a method can accept a different number of parameters of the same type. This feature is often used when you want to create methods that can accept an undecided number of parameters.
22. What are the types of classes in C#?
Here, below are types of classes in C#
1 - Abstract class
2 - Partial class
3 - Sealed class
4 - Static class
23. What is class in C#?
A class is basic pillar of OOP that is called when instance of a class is created. A class can have fields, properties, method, constructor and destructor etc. When we create an instance of class. This instance of class is used to access of fields, methods, properties, constructor (constructor can zero argument or multiple argument) and destructor. A class is reference type and stores in heap.
24. What is constructor in C#?
Constructor is special method that called when object/instance of class is created
25. What is destructor in C#?
Destructor is also a special method that called when object/instance of class is destroyed.
26. What is static class in C#?
In C#, a static is a keyward that is used with fields, methods, properties and classes when we make these members static they are globally accessble in all over the application.
Rules for Making Static Class
Here we have defined some rules of making static class.
Declaration
A static class must be declared using the static keyword.
Static Members:
All members (methods, properties, fields) of a static class must also be static.
Instantiation:
Static classes cannot be instantiated; you cannot create an object of a static class.
Instance Members:
Static classes cannot contain instance members (non-static fields or methods).
Static Methods:
A static class can contain static methods, which can be called without creating an instance.
Static Constructor:
A static class can have a static constructor for initialization purposes, which is called automatically before any static members are accessed.
Accessibility:
Static classes are sealed class and therefore, cannot be inherited. A static class cannot inherit from other classes.
27. What is static method in C#?
A Static method is also accessible all over the application globally. When we want that a method will be accessible in all over the application with creating the instance of class then we make it static.
*Rules for making Static Methods
*
Here we have defined some rules of making static method.
Accessibility Modifiers
Static methods can have access modifiers (e.g., public, private) that determine their visibility outside the class
Inheritance:
Static methods are not polymorphic. You cannot override a static method in a derived class; however, you can hide it by declaring a static method with the same name.
No this Keyword:
Inside a static method, you cannot use the this keyword since there is no instance context.
Calling:
You can call static methods using the class name, or from other static methods within the same class without needing to specify the class name.
No Access to Instance Members:
Static methods cannot access instance variables or instance methods directly. They can only interact with static members.
28. What is static constructor in C#?
A non-static class can contain a zero-argument static constructor. It can be defined with the static keyword and without access modifiers like public, private, and protected.
Note:The static constructor gets called when you create an instance for the first time.
Static Constructor Example
// First static constructor and then instance constructor called
Fruit sw1 = new Fruit();
// only instance constructor called
Fruit sw2 = new Fruit();
Rules for making Static Constructors
Here we have defined some rules of making static constructor.
Declaration
A static constructor is defined with the static keyword and does not have any parameters.
Initialization Timing:
It is called automatically before any static members are accessed or any instance of the class is created.
Single Invocation:
The static constructor is called only once per type, regardless of how many instances of the class are created.
No Parameters:
They cannot take parameters, which means they can’t be overloaded.
Inheritance:
If a derived class has a static constructor, the base class's static constructor is called first.
29. What is struct in C#?
A struct a value type and it store it's data in stack. Classes are reference type and it store it's data in heap. The structs are usually used for small data structures. The structs are specially used when we don't need features of classes like inheritance.
Suppose we want to store the name and color of a fruit. We can create two variables: name and color and store value. However, suppose we want to store the same information of multiple fruit.
In this case, creating variables for an individual fruit might be a tedious task. To overcome this we can create a struct that stores name and color. Now, this struct can be used for every fruit.
30. What is enum in C#?
The enum is also called enumeration. It is a value type. Enum is used to define the set of named constant values
For reading complete above tutorial please visit following link :_ c# interview questions
For more such type of tutrials please visit this site: C-Sharp Tutorial
Thanks for reading.
Top comments (0)