Back to notes
How does the `checked` keyword in C# help prevent errors?
Press to flip
The `checked` keyword is used to explicitly enable overflow-checking for arithmetic operations and conversions so that an exception is thrown if an overflow occurs, helping to prevent unintended data loss.
What are some operators available in C# and their categories?
C# provides various operators: Arithmetic (+, -, *, /, %), Comparison (==, !=, >, <, >=, <=), Logical (&&, ||, !), and Bitwise (&, |, ^, ~).
Provide an example of a scope in C# and explain its significance.
In C#, the scope of a variable determines its visibility and accessibility within certain parts of the code, such as a variable defined inside a method being visible only within that method.
What does it mean for C# to be a statically typed language?
Being statically typed means that variable types are known at compile time in C#, allowing for type checking and avoiding type-related errors at runtime.
Can you list and explain the naming convention styles commonly used in C#?
Common C# naming conventions include CamelCase for local variables, PascalCase for methods and classes, and Hungarian Notation which prefixes variables with a small letter indicating type.
What is the primary purpose of the Common Language Runtime (CLR) in the .NET framework?
The CLR is responsible for executing .NET applications by translating intermediate language (IL) code into machine code using Just-In-Time compilation, allowing applications to run on any machine with CLR.
What are the main categories of types in C#?
Types in C# are categorized into primitive types (like Int, Float, Char, Bool) and non-primitive types (such as classes and arrays, covered in subsequent lessons).
Describe the potential problem of data type overflow and how C# addresses it.
Data type overflow occurs when a variable exceeds its allocated memory size, potentially causing unexpected results. C# can address this with the `checked` keyword to enforce overflow checking.
Describe the difference between single-line and multi-line comments in C#.
Single-line comments use // and are used for short comments, while multi-line comments use /* comment */ and are used for longer explanations.
How does C# handle type sensitivity?
C# is case sensitive, meaning it treats identifiers with different cases as distinct, which affects variable naming and method usage.
How can you declare a constant in C# and why are constants used?
Constants in C# are declared using the `const` keyword, and they represent immutable values that remain the same throughout the program execution, set at compile time, ensuring consistent values.
List the integral primitive types available in C#.
The integral primitive types in C# include Byte, Short, Int, and Long.
What is operator precedence and its significance in C#?
Operator precedence determines the order in which operators are evaluated in expressions, with multiplication and division evaluated before addition and subtraction, ensuring correct calculations.
Explain the importance of naming conventions in C#.
Naming conventions improve code readability and maintainability by providing a consistent way of naming variables and methods, such as CamelCase for local variables and PascalCase for method names.
What distinguishes C# from the .NET framework?
C# is a programming language, whereas .NET is a framework that provides tools and libraries for building applications on Windows.
Previous
Next