Structured Programming - C# Questions Bank PDF
Document Details
Uploaded by ImpressedSynergy3690
Mansoura National University
Tags
Summary
This document is a collection of questions and answers related to structured programming concepts in C#. The questions cover topics such as data types, operators, and basic syntax, making it a useful resource for C# learners or those looking to practice related skills.
Full Transcript
Structured Programming - C# Questions Bank Section: Introduction 1. What is the purpose of the 'Main' method in a C# program, and how is it declared? 2. Briefly describe what a compiled language is and provide an example. 3. Explain the function of the 'using' keyword in a C# program. 4. How do...
Structured Programming - C# Questions Bank Section: Introduction 1. What is the purpose of the 'Main' method in a C# program, and how is it declared? 2. Briefly describe what a compiled language is and provide an example. 3. Explain the function of the 'using' keyword in a C# program. 4. How do you write single-line and multi-line comments in C#? 5. What makes C# an object-oriented programming language? Section: Basic Syntax 6. How do you declare a variable in C# with an initial value? 7. What is the correct way to write a single-line comment in C#? 8. Write a simple 'if-else' statement in C# to check if a number is positive or negative. 9. How can you take input from a user using the 'Console.ReadLine()' method? 10. What are some naming conventions for variables in C#? Section: Data Types 11. Name three common data types in C# and provide a brief description of each. 12. What is the difference between 'float' and 'double' data types in C#? 13. How is a 'char' type different from a 'string' type in C#? 14. Write the syntax for declaring a boolean variable and assign it a value. 15. What is the range of the 'int' data type in C#? Section: Operators 16. How does the assignment operator '=' work in C#? 17. Provide an example of how the increment '++' operator is used in a loop. 18. Explain the difference between the '&&' and '||' logical operators. 19. What is the output of the expression: 15 % 4 in C#? 20. How does the conditional operator (?:) simplify conditional statements? Answers Section 1. The 'Main' method is the starting point of a C# program. It is declared as: static void Main(string[] args). 2. A compiled language translates code into machine code before execution. Example: C#. 3. The 'using' keyword allows the inclusion of namespaces to access classes without full qualification. 4. Single-line comment: // Comment, Multi-line comment:. 5. C# uses concepts like classes, inheritance, and polymorphism, making it object-oriented. 6. Syntax: int number = 10; 7. Use // to write a single-line comment. 8. if (number > 0) { Console.WriteLine("Positive"); } else { Console.WriteLine("Negative"); } 9. Use Console.ReadLine() to read input from the user. 10. Use camelCase for local variables and PascalCase for class names. 11. int: whole numbers, double: decimals, bool: true/false values. 12. 'float' has 7-digit precision, 'double' has 15-digit precision. 13. 'char' represents a single character, 'string' is a sequence of characters. 14. bool isTrue = true; 15. The 'int' type ranges from -2,147,483,648 to 2,147,483,647. 16. '=' assigns the right-hand value to the left-hand variable. 17. Example: for (int i = 0; i < 5; i++) { Console.WriteLine(i); } 18. '&&' is true if both conditions are true, '||' is true if at least one condition is true. 19. 15 % 4 equals 3. 20. The conditional operator (?:) returns one of two values based on a condition. Example: result = (x > 5) ? 10 : 5;