2. C# Language Basics || C# 10 Flashcards
What is a statement block?
Series of statement surrounded by a pair of braces (all of this is a method)
int feetToInches (int feet) { return 12 * feet; }
What is an “assembly”?
Assemblies are the fundamental units of deployment, version control, reuse, activation scoping, and security permissions for .NET-based applications. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. Assemblies take the form of executable (.exe) or dynamic link library (.dll) files, and are the building blocks of .NET applications. They provide the common language runtime with the information it needs to be aware of type implementations.
In .NET and .NET Framework, you can build an assembly from one or more source code files. In .NET Framework, assemblies can contain one or more modules. This way, larger projects can be planned so that several developers can work on separate source code files or modules, which are combined to create a single assembly.
Assemblies have the following properties:
Assemblies are implemented as .exe or .dll files. For libraries that target .NET Framework, you can share assemblies between applications by putting them in the global assembly cache (GAC). You must strong-name assemblies before you can include them in the GAC. Assemblies are only loaded into memory if they're required. If they aren't used, they aren't loaded. Therefore, assemblies can be an efficient way to manage resources in larger projects. You can programmatically obtain information about an assembly by using reflection. You can load an assembly just to inspect it by using the MetadataLoadContext class on .NET and .NET Framework. MetadataLoadContext replaces the Assembly.ReflectionOnlyLoad methods.
Name some predefined and custom types. What is the main difference between them?
Predefined: string, int, bool;
Custom: Person, Salary, Payment;
Predefined types dont need to be instantiated like custom does:
int three = 3; Person jack = new Person(“Jack”);
How would you describe static class?
Static members (data and function members) dont operate on the instance of the type e.g. Console.WriteLine()
and not var x = new Console
. Methods of the static class are available through class name (Console) and not instance name (x).
What is a implicit conversion?
short -> int -> long;
Implicit conversion happens automatically: int -> long
Allowed when both are true:
1. The compiler can garuantee that they will always succeed;
2. No information is lost in conversion;
What is an explicit conversion?
Explicit conversion require a cast and this type of conversion is required when one of the following is true:
1. The compiler cannot garuantee that they will always succeed
2. Information might be lost during conversion
What are the types categories in C#?
• Value types
• Reference types
• Generic type parameters
• Pointer types
Which types lay under the value type? (Name more than 3)
Value types comprise most built-in types (all numeric types, char and bool types) as well as custom struct and enum types
Which types lay under reference type?
All classes, array, delegate, interface types. Includes predefined string type as well
What is the fundamental difference between value and reference types?
The way they are handled in memory. Value type objects are always copied or created, but assigning a reference type the reference is copied not the object instance.
What are nullable variables?
Variables which references points to no objects. Thats why we get NullReferenceException
. This also means that value type cannot have a null as value if not declared otherwise (?)
What is the difference between i++ and ++i?
Both are adding 1 to the variable, but the difference is whether we want variable’s value before or after the increment:
console.writeline(x++);
outputs 0; value is now 1;
console.writeline(++x);
outputs 1; value is 1;
What is “short-circuiting”? Where it is encountered?
It is encountered when using && and || operators in a condition (comparing to & and |). In short if the first part of the condition is not true the following part is not evaluated, therefore if the first statement is false this statement wont throw a NullReferenceException
If ( sb != null && sb.Length >0)…
What is a ternary operator?
Ternary operator ( condotional operator or shorthand if statement) - has the form “question ? AnswerA : AnswerB”
Give an example of verbatim string
var string = @“\\server\files\heloworld.cs”;
It can also support multiple line strings