C# Basics
C# Basics
a) void myMethod()
b) int myMethod()
c) double myMethod()
d) string myMethod()
a) new
b) var
c) using
d) alias
Answer: b) var
a) try
b) catch
c) exception
d) handle
Answer: b) catch
a) "IEnumerable" is used for querying in-memory collections, while "IQueryable" is used for querying
databases.
d) "IEnumerable" is used for querying databases, while "IQueryable" is used for querying in-memory
collections.
Answer: a) "IEnumerable" is used for querying in-memory collections, while "IQueryable" is used for
querying databases.
What is the purpose of the "using" statement in C# when working with resources?
In C#, what is the difference between a value type and a reference type?
a) Value types are stored on the heap, while reference types are stored on the stack.
b) Value types can be null, while reference types cannot.
c) Value types are passed by reference, while reference types are passed by value.
d) Value types store the actual data, while reference types store the memory address of the data.
Answer: d) Value types store the actual data, while reference types store the memory address of the
data.
a) "is" operator checks if an object can be cast to a given type, while "as" operator performs the
actual casting.
b) "is" operator checks for object equality, while "as" operator checks for reference equality.
c) "is" operator performs explicit casting, while "as" operator performs implicit casting.
d) "is" operator is used for value types, while "as" operator is used for reference types.
Answer: a) "is" operator checks if an object can be cast to a given type, while "as" operator performs
the actual casting.
What is the purpose of the "yield" keyword in C# when used with iterators?
b) It is used to define the application's entry point for the operating system.
c) It is used to specify command-line arguments for the program.
How can you prevent a class from being inherited by other classes in C#?
c) By using the "protected" access modifier for all members of the class.
Given an array of integers, write a C# program to find the maximum and minimum values in the
array.
Given a sentence, write a C# program to count the number of words in the sentence.
Write a C# program to find the factorial of a given number using recursion.
Given two sorted arrays, write a C# program to merge them into a single sorted array.
Write a C# program to find the area of a triangle given the lengths of its three sides using Heron's
formula.
What is C#?
Which of the following access modifiers allows a class member to be accessed from anywhere in the
same assembly?
a) private
b) protected
c) internal
d) public
Answer: c) internal
Which C# data type is used to store whole numbers without decimal points?
a) float
b) double
c) decimal
d) int
Answer: d) int
b) To declare variables
d) To define loops