0% found this document useful (0 votes)
481 views13 pages

C# Test

The document contains details about an online course titled "Advanced CSharp Programming for Beginners". It lists the various modules and topics covered in the course along with the estimated time to complete each module. Some of the key modules include Exception Handling, Generics, Collections, Delegates, LINQ, File Handling, Asynchronous Programming, and Memory Management. The document also includes sample questions from assessments and links to additional learning resources.

Uploaded by

pankaj.mahadik56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
481 views13 pages

C# Test

The document contains details about an online course titled "Advanced CSharp Programming for Beginners". It lists the various modules and topics covered in the course along with the estimated time to complete each module. Some of the key modules include Exception Handling, Generics, Collections, Delegates, LINQ, File Handling, Asynchronous Programming, and Memory Management. The document also includes sample questions from assessments and links to additional learning resources.

Uploaded by

pankaj.mahadik56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Page Loaded

Skip To Main Content


Contents
Details
thumbnail
Advanced CSharp Prog...
Course | Beginner
70h 10m
done

folder
Prelude
7m 56s
done_all
folder
Exception Handling
3h 1m
done_all
folder
Generics
2h 4m
done_all
folder
Collections
5h 53m
done_all
folder
Day 1 Assignments
30m
done_all
folder
CSharp language enhancements
3h 49m
done_all
folder
Delegates
3h 40m
done_all
folder
Day 2 Assignments
1h 17m
done_all
folder
Delegates Enhancements
4h 43m
done_all
folder
Extension Methods
30h 42m
done_all
folder
LINQ - Language Integrated Query
5h 13m
done_all
folder
Day 3 Assignments
1h 40m
done_all
folder
File Handling
1h 38m
done_all
folder
Asynchronous Programming
58m 14s
done_all
folder
Memory Management
1h 33m
done_all
folder
Day 4 Assignments
1h 26m
done_all
folder
Conclusion
50m
done_all
web_asset
Best Practices
5m
done_all
web_asset
View CSharp videos in Digital ...
5m

Q1 of 25
Anonymous methods allow code blocks to be written ___________.

"in-line" where 'property' values are expected.


"in-line" where 'indexer' values are expected.
"in-line" where 'delegate' values are expected.
"in-line" where 'field' values are expected.
Q2 of 25
While creating the List<TEntity> instance, the Capacity property is set to 3. What
will be the capacity when 4th element is added to the collection?

4
6
8
Error : 4th element cannot be added
Q3 of 25
When designing a class, it is recommended to avoid using the Finalize() method.

Choose the correct option for the reason.

(i) Finalizable objects requires longer time to allocate


(ii) Calling garbage collector to execute a Finalize method hurts performance
(iii) Programmer don't have control on the Finalize method execution

All (i), (ii) and (iii)


Only (i) and (ii)
Only (i) and (iii)
Only (ii) and (iii)
Q4 of 25
Arrange the below in the order of Garbage collection while reclaiming the memory.

(i) The garbage collector frees objects that are not referenced and reclaims
their memory
(ii) The garbage collector searches for managed objects that are referenced in
managed code
(iii) The garbage collector tries to finalize objects that are not referenced

ii, i, iii
i, iii, ii
iii, ii, i
ii, iii, i
Q5 of 25
What will be the output of the following code snippet?

class Program
{
private static string result;

static async Task<string> GreetUser()


{
result = "Hello world!";
await Task.Delay(5);
return "Hello user!";
}

static void Main(string[] args)


{
GreetUser();
Console.WriteLine(result);
}
}

Hello world!
Hello user!
Compilation Error - Incorrect usage of 'async' and 'await' keywords
The code executes without displaying any output
Q6 of 25
What will be output for the below code snippet?

class MyClass : IDisposable


{
public void Dispose() { Console.WriteLine("Dispose()"); }
}
class Program
{
public static void Main(string[] args)
{
MyClass myObj1 = new MyClass();
myObj1.Dispose();
using (MyClass myObj2 = new MyClass())
{

}
}
}
Choose the following option:

a. Dispose()
Dispose()

b. Dispose()

c. Compilation Error - Dispose method cannot be invoked explicitly

d. Exception - Dispose method cannot be invoked explicitly

Option a
Option b
Option c
Option d
Q7 of 25
Predict the output of the below code snippet:

public delegate int CalculatorDelegate(int n1, int n2);


class Program
{
static void Main(string[] args)
{
CalculatorDelegate addDel = new CalculatorDelegate(Addition);
CalculatorDelegate subDel = new CalculatorDelegate(Subtraction);
CalculatorDelegate mulDel = new CalculatorDelegate(Multiplication);

CalculatorDelegate resultDel = addDel - subDel + mulDel;

Console.WriteLine(resultDel(12,10));
}
static int Addition(int num1, int num2)
{
return (num1 + num2);
}
static int Subtraction(int num1, int num2)
{
return (num1 - num2);
}
static int Multiplication(int num1, int num2)
{
return (num1 * num2);
}
}
140
144
120
142
Q8 of 25
What will be the output for the below given code snippet:

SortedList sortList= new SortedList();


sortList.Add(10, null);
sortList.Add(null, "Chennai");
sortList.Add(30, "Chennai");
sortList.Add(20, "Bangalore");
Exception - Key cannot be null
Compile time error - Value cannot be null
Exception - Value cannot be null
Exception - Duplicate values are not allowed
Q9 of 25
What is the output of the following program?

class Program
{
public static void Main()
{
SortedList myList = new SortedList();
myList.Add('m', "Harry");
myList.Add('a', "Mark");
myList.Add('b', "Scott");
myList.Add('h', "John");
myList.Add('d', "Larry");
Console.WriteLine(myList.ElementAt(1).Value);
}
}
Mark
Larry
Harry
Scott
Q10 of 25
Identify the invalid statements among the following:

var z = null;
var v = 3;
var x = x++;
var y = new[] {1, 2, 3};
Q11 of 25
Which of the following statements about Generics is FALSE?

(a) Use generic types to maximize type safety, and improve performance

(b) Generics has introduced the concept of type parameters in .NET Framework

Only (a)
Only (b)
Both (a) and (b)
Neither (a) nor (b)
Q12 of 25
What will be the output of the following code snippet?

class Demo
{
static void Main(string[] args)
{
int value1 = 10;
int value2 = 20;
int[] myArray = { 1, 2, 0 };
try
{
double result = value1 / myArray[4];
try
{
double result2 = value2 / myArray[2];
}
catch (Exception e1)
{
Console.Write("one ");
}
finally
{
Console.Write("finally ");
}
}
catch (IndexOutOfRangeException e2)
{
Console.Write("two ");
}
catch (DivideByZeroException e3)
{
Console.Write("three ");
}
}
}
Choose from the following option:

a. two
finally

b. one
finally

c. Compile Time Error - The generic exception cannot appear before the specific
exception

d. finally
two

e. two

Option a
Option b
Option c
Option d
Option e
Q13 of 25
Consider the following code snippet:

public class Program


{
public delegate int Calc(int x, int y);
public delegate int Calc(double x, int y);
}
Which of the following statement is TRUE?

This is an example of Multicast delegate


This is an example of delegate overloading
In the context of delegates, the signature of a delegate does not include the
return value. Hence in the code snippet, return type 'int' should be replaced with
return type 'void'
Compile Time Error: The Type Program already contains a definition for Calc. This
error is due to statement 'public delegate int Calc(double x, int y)'
Q14 of 25
Consider the following code snippet:

public class Employee


{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Department { get; set; }
}
static void Main(string[] args)
{
List<Employee> empTree = new List<Employee>();
empTree.Add(new Employee { FirstName = "James", LastName = "Cameroon",
Department = "IT" });
empTree.Add(new Employee { FirstName = "Tom", LastName = "Hanks",
Department = "Marketing" });
empTree.Add(new Employee { FirstName = "Brad", LastName = "Pitt",
Department = "IT" });
empTree.Add(new Employee { FirstName = "Tom", LastName = "Cruise",
Department = "Sales" });
empTree.Add(new Employee { FirstName = "Angelina", LastName = "Jolie",
Department = "Sales" });
empTree.Add(new Employee { FirstName = "Leonardo", LastName =
"DiCaprio", Department = "Marketing" });

// LINQ query missing here

foreach (var dept in employeesByDept)


{
Console.WriteLine("Department: {0}", dept.Key);
foreach (var emp in dept)
{
Console.WriteLine("\t{0} {1}", emp.FirstName, emp.LastName);
}
}
}
What is the appropriate LINQ query to be written inside the Main() method, to
produce the following output?

var employeesByDept = from e in empTree group e by e.Department;


var employeesByDept = from e in empTree group e by e.FirstName;
var employeesByDept = from e in empTree group e.Department;
var employeesByDept = from e in Employee group e by e.Department;
Q15 of 25
Consider the following code snippet:

static void Main(string[] args)


{
string[] fruitsList = { "Grapes", "Apple", "Gooseberry", "Blueberry",
"Apricot", "Guava", "Banana"};

// LINQ query to be written here

foreach (var item in fruitsResult)


{
Console.WriteLine(item.Key);
foreach (String str in item)
Console.WriteLine(str);
Console.WriteLine();
}
}
Identify the suitable LINQ query to be written inside the Main() method, so that it
results in the following output?

a. var fruitsResult = from fruits in fruitsList group fruits by


fruits.Substring(0, 1) into fruitGroups orderby fruitGroups.Key select fruitGroups;

b. var fruitsResult = from fruits in fruitsList group fruits by fruits.Substring(0,


1) into fruitGroups orderby fruitGroups select fruitGroups;

c. var fruitsResult = from fruits in fruitsList group fruits by fruits.Substring(0,


1) into fruitGroups select fruitGroups;

d. var fruitsResult = from fruits in fruitsList group fruits by fruits.Substring(0,


1) into fruitGroups orderby fruitGroups.Key descending select fruitGroups;

Option a
Option b
Option c
Option d
Q16 of 25
Consider the following code snippet:

public class Employee


{
public string FirstName { get; set; }
public string Designation { get; set; }

public static List<Employee> GetEmployees()


{
return new List<Employee>
{
new Employee { FirstName="Charles", Designation = "Technical
Architect" },
new Employee { FirstName="Fleming", Designation = "Project Manager"
},
new Employee { FirstName="Anderson", Designation = "Team Leader" },
new Employee { FirstName="Stephen", Designation = "Systems
Engineer" }
};
}
public override string ToString()
{
return string.Format("{0, -20}: {1, -20}", FirstName, Designation);
}
}
static void Main(string[] args)
{
List<Employee> employees = Employee.GetEmployees();

// Lambda Expression code goes here

foreach (Employee employee in employees)


{
Console.WriteLine(employee);
}
}
Identify the proper Lambda Expression code to be written inside the Main() method,
so that it produces the following output?

employees.Sort((first, second) => first.Designation.CompareTo(second.Designation));


employees.Sort((first, second) => second.Designation.CompareTo(first.Designation));
employees.Search((first, second) =>
first.Designation.CompareTo(second.Designation));
employees.Sort((first, second) => first.FirstName.CompareTo(second.FirstName));
Q17 of 25
Consider the following code snippet:

public delegate bool CheckString(string str);

public static List<string> FilterStrings(string[] input, CheckString


filter)
{
List<string> resultList = new List<string>();
foreach (string item in input)
{
if (filter(item))
resultList.Add(item);
}
return resultList;
}
static void Main(string[] args)
{
string[] input = { "One", "Two", "Three", "Four", "Five" };

List<string> output = ______________ // LINE 01

foreach (string item in output)


Console.WriteLine(item);
}
Identify the appropriate code snippet that has to be written in LINE 01 in Main()
method, so that it gives the following output when executed?

FilterStrings(input, str => str.Length > 3);


FilterStrings(input, str => str.Length >= 3);
FilterStrings(str => str.Length > 3, input);
FilterStrings(str => str.Length >= 3, input);
Q18 of 25
Identify which of the built-in delegate is used in the following Lambda Expression
(the code underlined below).

bool asiaCustomers = customers.All(c => c.Region == "Asia");

Func<>
Action<>
Predicate<>
MulticastDelegate
Q19 of 25
Consider the following code snippet:
static void Main(string[] args)
{
#region Demo on File Handling

FileStream fileStream = File.Create("Log.txt");

StreamWriter writer = new StreamWriter(fileStream);


writer.Write("Example on File Handling - StreamWriter class");
writer.Close();

// LINE 01 - code to open the file "Log.txt" and read the contents from
it

StreamReader reader = new StreamReader(fileStream);


string text;
while ((text = reader.ReadLine()) != null)
{
Console.WriteLine(text);
}
writer.Close();
fileStream.Close();
}
Identify the code snippet from the given options that can be written inside the
Main() method at LINE 01, to read the contents of the file that is created during
the execution of the program?

fileStream = File.Open("Log.txt", FileMode.Append, FileAccess.Read);


fileStream = File.Open("Log.txt", FileMode.Open, FileAccess.Read);
fileStream = File.Open("Log.txt", FileMode.Truncate, FileAccess.ReadWrite);
fileStream = File.Open("Log.txt", FileMode.Truncate, FileAccess.Read);
Q20 of 25
Consider the following code snippet:

static class StringExtension


{
public static bool IsCapitalized(this string s) {...}
}
static class ObjectExtension
{
public static bool IsCapitalized(this object s) {...}
}
Which among these two extension methods is called, when the following invocation
happens?

bool result = "india".IsCapitalized();


a. ObjectExtension's IsCapitalized() method is executed

b. StringExtension's IsCapitalized() method is executed

c. Both the methods will be executed, but in the following sequence


ObjectExtension's IsCapitalized() method is executed first
StringExtension's IsCapitalized() method is executed overwriting the output of
the previous method

d. Both the methods will be executed, but in the following sequence


StringExtension's IsCapitalized() method is executed first
ObjectExtension's IsCapitalized() method is executed overwriting the output of
the previous method

Option a
Option b
Option c
Option d
Q21 of 25
What will be the output of the following code snippet?

static void Main(string[] args)


{
var at1 = new { X = 2, Y = 4 };
var at2 = new { X = 2, Y = 4 };

Console.WriteLine(at1.GetType() == at2.GetType());
Console.WriteLine(at1 == at2);
Console.WriteLine(at1.Equals(at2));
}
Choose the correct option:

a. True
True
True

b. True
False
False

c. True
False
True

d. False
True
False

Option a
Option b
Option c
Option d
Q22 of 25
Consider the following code snippet:

public class Employee


{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Designation { get; set; }
}
public class Role
{
public int RoleId { get; set; }
public string RoleName { get; set; }
}
static void Main(string[] args)
{
List<Employee> employees = new List<Employee>
{
new Employee { FirstName = "John", LastName = "Donne",
Designation = 2 },
new Employee { FirstName = "William", LastName = "Shakespeare",
Designation=1 },
new Employee { FirstName = "William", LastName = "Wordsworth",
Designation=2 },
new Employee { FirstName = "Geoffrey", LastName = "Chaucer",
Designation=2 }
};

List<Role> roles = new List<Role>


{
new Role { RoleId = 1, RoleName = "Manager" },
new Role { RoleId = 2, RoleName = "Developer" }
};

// LINE 01 - code for LINQ query goes here

foreach (var item in query)


{
Console.WriteLine("{0, -20} {1, -20} {2, -5}",
item.FirstName, item.LastName, item.RoleName);
}
}
Identify the appropriate LINQ query that needs to be written inside Main() method
at LINE 01, so that it produces the following output on execution?

a. var query = from e in employees join r in roles on e.Designation = r.RoleId


orderby r.RoleName select new { e.FirstName, e.LastName, r.RoleName };

b. var query = from e in employees join r in roles on e.Designation == r.RoleId


orderby r.RoleNameelect new { e.FirstName, e.LastName, r.RoleName };

c. var query = from e in employees join r in roles on e.Designation equals r.RoleId


orderby r.RoleName select new { e.FirstName, e.LastName, r.RoleName };

d. var query = from e in employees join r in roles on e.Designation equals r.RoleId


select new { e.FirstName, e.LastName, r.RoleName };

Option a
Option b
Option c
Option d
Q23 of 25
Which of the following statement(s) about built-in delegates are TRUE?

(a) Func delegate can take parameters and must return any value

(b) Action delegate doesn't take parameters and doesn't return a value

(c) Predicate delegate can take parameters but returns only int value

Only (b) and (c)


Only (a)
All (a), (b) and (c)
Only (a) and (c)
Only (c)
Q24 of 25
Consider the following code snippet:

static void Main(string[] args)


{
Dictionary<string, short> isdCodes = new Dictionary<string, short>();
isdCodes.Add("Germany", 49);
isdCodes.Add("Australia", 61);
isdCodes.Add("Mexico", 52);
isdCodes.Add("Spain", 34);
isdCodes.Add("Sweden", 46);
isdCodes.Add("India", 91);

// LINE 01 - code to written here for filtering the desired result

foreach (var item in result)


{
Console.WriteLine(item.Key + "\t" + item.Value);
}
}
Identify the code snippet which needs to be written at LINE 01 of the Main()
method, so that it produces the result as "India 91" when executed?

var result = isdCodes.Where(c => c.Value > 50 && c.Value.Length == 5);


var result = isdCodes.Where(c => c.Value > 50 && c.Key.Length == 5);
var result = isdCodes.Where(c => c.Value > 50 || c.Key.Length == 5);
var result = isdCodes.Where(c => c.Key.Length == 5);
Q25 of 25
Which among the following option holds good for Extension Methods in C#?

Extension methods allows us to modify the method present in an existing type


through inheritance
The return type of the extension method will be the type that is extended
The first parameter of the extension method uses 'base' modifier followed by the
type that is being extended
Extension methods are helpful in scenarios where the class is sealed and yet one
wants to extend its functionality, without the concept of inheritance

You might also like