Imperative programming constructs (C#) Flashcards

1
Q

What are imperative programming constructs?

A

Imperative programming constructs are statements or commands in a programming language that are used to control the flow of execution and perform operations on data. They are used to express the logic of the program in a step-by-step manner

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

Give examples of imperative programming constructs in C#.

A
  1. Assigning values to variables
    2.Assigning instances to object references
  2. Performing operations on the values
  3. Calling methods on object references
  4. Selective execution using if statements and switch statements
  5. Repetitive execution using for loops, while loops, foreach loops, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is static type-checking?

A

It is a process that checks the type of the program during compile time.

The compiler checks whether the types of all variables, functions, and expressions in the program are compatible and will work correctly at runtime.

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

What are the advantages of static type-checking?

A
  1. Errors can be caught at compile-time, before the program is run.
  2. Can help to prevent type-related bugs and improve code quality.
  3. Can provide better performance, as the compiler can optimize code based on the known types.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the disadvantages of static type-checking?

A
  1. Can be more verbose, as types must be explicitly declared.
  2. Can be more difficult for beginners to understand, as it requires knowledge of type systems.
  3. Can be limiting in some cases, where dynamic behavior is desired.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is dynamic type-checking?

A

It is a process that checks the type of the program during runtime. In a dynamically typed language, the type of a variable or expression is determined at runtime, and the runtime checks if the types are compatible before executing the code.

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

What are the advantages of dynamic type-checking?

A
  1. Can be more concise, as types don’t need to be explicitly declared.
  2. Can be easier for beginners to understand, as it allows more flexibility in the code.
  3. Can be useful in cases where dynamic behavior is desired.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the disadvantages of dynamic type-checking?

A
  1. Errors may not be caught until runtime, which can make debugging more difficult.
  2. Can be slower in some cases, as the runtime must perform type checks.
  3. Can be more prone to type-related bugs if not used carefully.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is C# a static or dynamic type-checking language?

A

It is a statically typed language, which means that types are checked at compile-time rather than runtime.

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

What is a strongly-typed language?

A

It requires that all variables have a declared type and that the operations performed on them are consistent with that type.

This means that type errors are caught at compile-time, preventing potential runtime errors

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

What are the advantages of strongly-typed languages?

A

It helps catch errors at compile-time, which can save time and effort in debugging.

It also allows for better code optimization and can improve performance.

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

What are the disadvantages of strongly-typed languages?

A

It can be restrictive and can lead to more verbose code.

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

Give examples of strongly-typed programming languages

A
  1. C#
  2. Java.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does weakly-typed languages allow?

A

They allow type coercion.

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

What does type coercion mean?

A

It means that a variable can change its type from one to another as needed. This can lead to errors and bugs that may only surface at runtime.

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

Give examples of weakly-typed programming languages

A
  1. JavaScript.
  2. PHP.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the advantages of weakly-typed languages?

A

It allows for more flexibility and can make code shorter and more concise.

It can also be easier to write code quickly and iterate rapidly.

18
Q

What are the disadvantages of weakly-typed languages?

A

It can lead to errors that may be difficult to track down, and can potentially cause security issues if not handled properly.

19
Q

Does C# have primitives?

A

C# has no primitives, everything is typed.

The compiler allows you to write certain objects in a native way, such as int, bool, and string.

20
Q

What is the equivalent of the primitive ‘int’ in C#?

A

The equivalent of the primitive ‘int’ in C# is System.Int32.

21
Q

What is the equivalent of the primitive ‘bool’ in C#?

A

The equivalent of the primitive ‘bool’ in C# is System.Boolean.

22
Q

What is the equivalent of the primitive ‘string’ in C#?

A

The equivalent of the primitive ‘string’ in C# is System.String.

23
Q

How does the compiler handle types in C#?

A

Types can be deduced by the compiler and operated on using methods. The compiler accepts a native usage of operands.

24
Q

What is the JIT compiler in C#?

A

It stands for “Just-In-Time” compiler, which allows the compiler to rewrite to native code, and hence optimize number types.

25
Q

What is type conversion in C#?

A

It allows variables to be compared for type and can be cast to any explicit type. C# allows the use of “typeof” keyword to extract type (in a safe way), “is” keyword to determine if a variable is equal or derived from a specific type, and “as” keyword to safely convert a variable to a type or null if the type cannot be coerced.

26
Q

What are implicit typed local variables in C#?

A

C# has a keyword “var” that allows for the use of implicit typing for local variables.

This helps to reduce duplicated typing and make the code more readable.

27
Q

What are the three types of operators that can be overloaded in C#?

A

Unary operators (+, -, !, ~, ++, -).
Binary operators (+, -, *, /, %). Comparative operators (==, !=, <, >, <=, >=)

28
Q

How are method overloads on custom types defined in C# for operator overloading?

A

They are defined as public static methods on the class using the “operator” keyword for operator overloading in C#.

29
Q

What is required for a unary operator overload in C#?

A

It must take one parameter of the same type and return one instance.

30
Q

What is required for a binary operator overload in C#?

A

It must take two parameters of the same type and return one instance.

31
Q

What is required for a comparative operator overload in C#?

A

It must take two parameters of the same type and return a bool value.

32
Q

What is null handling in C#?

A

It is a way to deal with null values or references in the code, which can lead to runtime errors and bugs.

33
Q

What are nullable value types in C#?

A

They allow value types, such as int or float, to be assigned null values.

34
Q

What are null propagators in C#?

A

They provide a concise way to check for null values before accessing properties or invoking methods.

They allow developers to write code in a more compact and readable way, while also reducing the risk of runtime errors.

35
Q

What is the null-coalescing operator in C#?

A

It is used to assign a default value to a variable when a null value is encountered.

It is a shorthand way of writing an if-else statement to check for null values and assign a default value if necessary.

36
Q

What is a design pattern in software development?

A

It is a general reusable solution to a commonly occurring problem in software development that is formalized as a best practice.

37
Q

What is a language idiom in software development?

A

It is a characteristic mode or expression that is commonly used and accepted in a particular programming language or framework.

38
Q

What is a code smell in software development?

A

It is a characteristic of the code that may indicate the presence of a deeper problem, such as poor design or implementation, and can lead to maintenance issues and bugs.

39
Q

Can design patterns evolve to features?

A

Yes, design patterns can evolve into language features in programming languages. This is because design patterns are based on common problems and solutions, and programming languages can adopt those solutions as built-in features to make programming easier and more efficient.

40
Q

What is string interpolation in C#?

A

It is a feature that allows you to embed expressions into string literals, making it easier to create strings with dynamic content.

It allows you to insert values of variables directly into a string without the need for concatenation using the + operator

41
Q

What are raw strings in C#?

A

It is a string that is marked with the ‘@’ character prefix, which allows it to contain escape characters and newlines without being interpreted as such.