C# fundamentals Flashcards

1
Q

What is the difference between C# and .dot Net?

A

dot Net is a framework, but C# is a programming language.

Before C#, we had C++/C, where the runtime used to convert the code to the machine’s native language. i.e. when we run the code for x86 or x64, the compiler compiles the code to x86 machines.

C# will create an IL code which is machine independent and CLR will convert it to the machine dependent based on the architecture.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain dot Net architecture.

A

Class is a basic block. We will group aLL classes under name spaces. we will group these name spaces under assembly. Many assembly forms an application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are naming conventions avaialble?

A

Camel casing: string firstName = “Bharath”

Pascal casing string FirstName = “Bharath”

Hungarian notation: string strFistName = “Bharath;

usually in C#, const are pascal casing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is overflowing?

A

byte u = 255 +1 //overflow to 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to delete a line?

A

ctrl+x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to add code snippet?

A

cw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to write format string?

A

console.writeline(“{0} {1} “, a, b);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

int.Parse()

A

used to convert int to string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why main method is static?

A

Because we can ensure that only one instance of Main can be there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is static keyword?

A
public class Person{
   static string name = "bharath";
}

Person.name;

It i snot associated with this keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to create an array?

A

int[] numbers = new int[5];

numbers[0] = 1

int[] numbers = new int[5] {1,2,3,4,5}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is verbatin string?

A

string str = @”C:\PF”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

There are three strings. We have to add a seprator and coine it to one string?

A

STring.join(“,”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to create an enum in c#?

A
public enum name{
 firstName: 1,
 middleName:2,
  lastname:3
}

to use name.FirstName;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to make enum as byte?

A
By default enum is of int datatype. To change it to byte:
public enum name : byte
{
 firstName: 1,
 middleName:2,
  lastname:3
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to convert an object to string?

A

every object will have ToSTring .

Also Console.WriteLine explicitly converts to string

17
Q

How to convert string to an object?

A

Use Parse method.

18
Q

What is difference between struct and class?

A

struct is a value type. Since it is a value type it is stored in stack and immediatly removed from stack when it goes out of scope.

Ref type are stored in heap. GC will clear.

19
Q

How to use forEach?

A

forEach(var i in numbers)
{
}

20
Q

How to check if the string is empty?

A

String.IsNullOrWhiteSpace

21
Q

What is the correct syntax to declare a rectangular 3x5 array?

A

var arr = new int[3,5]

22
Q

What is the difference between arrays and lists?

A

Arrays are fixed in size and Lists are dynamic

23
Q

What will be the output of this code?

var numbers = new List() { 1, 2, 3, 4, 5 };
var index = numbers.IndexOf(1);

Console.WriteLine(index);

A

0

24
Q

How can access the last element in a list?

A

list[list.Count -1]

25
Q

What are the types of arrays in c#?

A

Single dimenstional array

int[] arr = new int[5] {1,2,3,45]

Multidimensional array

var arr = new int [2,4] 
{
   {1,2},
   {4,6}
}

Jagged array

var arr = new int[2][];
arr[0] = new int[4];

arr[0][2] =1

26
Q

How to get length of an array?

A

Array.length

27
Q

How to reverse an array?

A

arr.reverse()

28
Q

How to find the position of an arrray?

A

Array.IndexOf(arr, 2)

29
Q

How to clear the array

A

Array.clear(arr,0 ,2)

clear will populate with the default value.

30
Q

How to copy an array?

A

Array.Copy(src, dest, hWmany)

31
Q

How to sort an array/

A

arr.sort()

32
Q

How to create a list?

A

var listDemo = new List() {1,2,3,4,5};

Lists are generics

33
Q

How to add to list?

A

listDemo.Add()

34
Q

How to add range?

A

listDemo.AddRange(new int[5] {5,6,7});

35
Q

How to iterate the list?

A

forEach(var number in Numbers)

36
Q

forEach and for difference?

A

In forEach we cannot modify the array/list such as remove