C# fundamentals Flashcards
What is the difference between C# and .dot Net?
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.
Explain dot Net architecture.
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.
What are naming conventions avaialble?
Camel casing: string firstName = “Bharath”
Pascal casing string FirstName = “Bharath”
Hungarian notation: string strFistName = “Bharath;
usually in C#, const are pascal casing
What is overflowing?
byte u = 255 +1 //overflow to 0
How to delete a line?
ctrl+x
How to add code snippet?
cw
How to write format string?
console.writeline(“{0} {1} “, a, b);
int.Parse()
used to convert int to string
Why main method is static?
Because we can ensure that only one instance of Main can be there.
what is static keyword?
public class Person{ static string name = "bharath"; }
Person.name;
It i snot associated with this keyword
How to create an array?
int[] numbers = new int[5];
numbers[0] = 1
int[] numbers = new int[5] {1,2,3,4,5}
What is verbatin string?
string str = @”C:\PF”
There are three strings. We have to add a seprator and coine it to one string?
STring.join(“,”)
How to create an enum in c#?
public enum name{ firstName: 1, middleName:2, lastname:3 }
to use name.FirstName;
How to make enum as byte?
By default enum is of int datatype. To change it to byte: public enum name : byte { firstName: 1, middleName:2, lastname:3 }