C# Flashcards
What is C#?
C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages on different computer platforms and architectures.
What is Jagged Array in C#?
A Jagged array is an array of arrays.
You can initialize a jagged array as −
int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}};
Where, scores is an array of two arrays of integers - scores[0] is an array of 3 integers and scores[1] is an array of 4 integers.
In how many ways you can pass parameters to a method?
There are three ways that parameters can be passed to a method −
Value parameters − This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.
Reference parameters − This method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
Output parameters − This method helps in returning more than one value.
Can you return multiple values from a function in C#?
Yes! Using output parameters. A return statement can be used for returning only one value from a function. However, using output parameters, you can return two values from a function.
What is the difference between ref and out parameters?
Output parameters are similar to reference parameters, except that they transfer data out of the method rather than into it. Reference parameter copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
What is namespace in C#?
Namespaces are used to organize classes and control the scope of a class.
What is the purpose of using statement in C
using keyword is used to include a namespace in the program. A program generally has multiple using statements.
What are value types in C#
Value type variables can be assigned a value directly. They are derived from the class System.ValueType.
The value types directly contain data. Some examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value.
What are reference types in C#
The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.
In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.
Which class acts as a base class for all the data types in .net?
The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class. The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion.
What is boxing in C#?
When a value type is converted to object type, it is called boxing.
What is unboxing in C#?
When an object type is converted to a value type, it is called unboxing.
What are dynamic type variables in C#
You can store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time.
Syntax for declaring a dynamic type is −
dynamic = value;
For example,
dynamic d = 20;
What is the difference between dynamic type variables and object type variables?
Dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at run time.
What are pointer types in C#?
Pointer type variables store the memory address of another type. Pointers in C# have the same capabilities as the pointers in C or C++.
Syntax for declaring a pointer type is −
type* identifier;
For example
char* cptr;
int* iptr;
What is the is operator for?
is operator determines whether an object is of a certain type.
If( Ford is Car) // checks if Ford is an object of the Car class.
What is the as operator for?
as operator casts without raising an exception if the cast fails.
Object obj = new StringReader("Hello"); StringReader r = obj as StringReader;
What is encapsulation?
Encapsulation is defined ‘as the process of enclosing one or more items within a physical or logical package’. Encapsulation, in object oriented programming methodology, prevents access to implementation details.
How encapsulation is implemented in C#?
Encapsulation is implemented by using access specifiers.
What is the purpose of an access specifier in C#?
An access specifier defines the scope and visibility of a class member.
What is scope of a public member variable of a C# class?
Public access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class.
What is scope of a private member variable of a C# class?
Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance of a class cannot access its private members.