Complete Exam Solution: .NET Framework, C#, ADO.NET Concepts
VerifiedAdded on 2023/04/21
|19
|2951
|290
Quiz and Exam
AI Summary
This document presents a comprehensive solution to a computer science exam focusing on .NET Framework, C#, ADO.NET, ASP.NET Core, and Angular concepts. The solution covers various topics, including defining the .NET framework, listing its components, discussing the advantages and disadvantages of value types inheriting from System.Object, explaining the implications of static methods, and analyzing C# code snippets. It also delves into ADO.NET, Entity Framework Core, error handling in ASP.NET Core projects, and social media login implementation. Furthermore, it examines TypeScript code files related to Angular development. The solutions are detailed and provide explanations for each step, offering valuable insights for students preparing for similar exams. Desklib provides past papers and solved assignments to help students excel.

IMPORTANT
• Not reading the examinable material and only practising sample exam is a
REALLY BAD IDEA
• Read the examinable lectures first, then only practise this exam
• In the final exam, you will be given space in the exam booklet to write
answers
• Always state your assumptions, if you are not sure about something. It helps the
marker to understand your thought process
• Do not use red ink/pen to write answers or label anything in the exam
Section A/ .NET framework, C# & ADO.NET [30 marks]
1. (4 marks) You have been asked to define the term .NET framework in an interview.
a. (1 mark) How will you define it in few words? Keep your answer to the point.
b. (3 marks) List (do not explain) the components of .NET framework.
a) .NET framework is software which runs on Microsoft windows operating system
b) - XML web services
- Console application
- Windows application
2. (2 marks = 1 + 1) All value types in C# inherit from System.Object. List one
advantage and one disadvantage of this approach.
Advantage – it is used to manage huge software systems and makes it easy to identify errors.
Disadvantage – the classes relation is normally artificial thus making it a bit tricky.
2
This is a sample exam only
• Not reading the examinable material and only practising sample exam is a
REALLY BAD IDEA
• Read the examinable lectures first, then only practise this exam
• In the final exam, you will be given space in the exam booklet to write
answers
• Always state your assumptions, if you are not sure about something. It helps the
marker to understand your thought process
• Do not use red ink/pen to write answers or label anything in the exam
Section A/ .NET framework, C# & ADO.NET [30 marks]
1. (4 marks) You have been asked to define the term .NET framework in an interview.
a. (1 mark) How will you define it in few words? Keep your answer to the point.
b. (3 marks) List (do not explain) the components of .NET framework.
a) .NET framework is software which runs on Microsoft windows operating system
b) - XML web services
- Console application
- Windows application
2. (2 marks = 1 + 1) All value types in C# inherit from System.Object. List one
advantage and one disadvantage of this approach.
Advantage – it is used to manage huge software systems and makes it easy to identify errors.
Disadvantage – the classes relation is normally artificial thus making it a bit tricky.
2
This is a sample exam only
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

3. (2 marks) Why is it considered a poor programming practice to have a lot of static
methods in a C# class? (do not just say- static belongs to a class and not object.) Explain
your answer briefly.
Static methods are referred to as Shared methods. When a method is defined as static then the
method now will belong to the type but not the instance. Methods which are static can't be
superseded or reached out through inheritance, (Richter, J. 2017).
4. (6 marks = 3 + 3) Consider the following C# code snippet and answer the question that
follows:
using System;
namespace ExamQuestion
{
class Program
{
static void Main(string[] args)
{
int[] i = new int[0];
Console.WriteLine(i[0]);
}
}
}
What will happen upon compilation of the above code segment?
Explain your answer briefly.
Outcome:
False
3
This is a sample exam only
methods in a C# class? (do not just say- static belongs to a class and not object.) Explain
your answer briefly.
Static methods are referred to as Shared methods. When a method is defined as static then the
method now will belong to the type but not the instance. Methods which are static can't be
superseded or reached out through inheritance, (Richter, J. 2017).
4. (6 marks = 3 + 3) Consider the following C# code snippet and answer the question that
follows:
using System;
namespace ExamQuestion
{
class Program
{
static void Main(string[] args)
{
int[] i = new int[0];
Console.WriteLine(i[0]);
}
}
}
What will happen upon compilation of the above code segment?
Explain your answer briefly.
Outcome:
False
3
This is a sample exam only

Explanation:
According to (Troelsen & Japikse, 2015), This is an empty array which also has empty
collection thus must give an empty output.
According to (Troelsen & Japikse, 2015), This is an empty array which also has empty
collection thus must give an empty output.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

5. (3 marks) In assignment 1 you were asked to store all the data in a Microsoft SQL Server
database.
Now consider a scenario where you have been asked to use data structures only for storing
data. You have been told that you cannot use an Array.
Which data structure would you choose? Justify your choice by providing an
example or a diagram.
List < >
Example in diagram
database.
Now consider a scenario where you have been asked to use data structures only for storing
data. You have been told that you cannot use an Array.
Which data structure would you choose? Justify your choice by providing an
example or a diagram.
List < >
Example in diagram
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

6. (10 marks) Consider the following ADO.NET code snippet and answer the questions that
follow:
…
SqlConnection conn = null;
SqlDataReader reader = null;
string inputIP = "131.170.27.121";
try
{
conn = new SqlConnection("some connection string");
conn.Open();
SqlCommand cmd =
A new SqlCommand("select * from log where ip = @IP",conn);
SqlParameter param = new SqlParameter();
param.ParameterName = "@IP";
param.SqlDbType = SqlDbType.VarChar;
B param.Size = 15;
param.Direction = ParameterDirection.Input;
param.Value = inputIP;
cmd.Parameters.Add(param);
reader = cmd.ExecuteReader();
…
}
5
This is a sample exam only
follow:
…
SqlConnection conn = null;
SqlDataReader reader = null;
string inputIP = "131.170.27.121";
try
{
conn = new SqlConnection("some connection string");
conn.Open();
SqlCommand cmd =
A new SqlCommand("select * from log where ip = @IP",conn);
SqlParameter param = new SqlParameter();
param.ParameterName = "@IP";
param.SqlDbType = SqlDbType.VarChar;
B param.Size = 15;
param.Direction = ParameterDirection.Input;
param.Value = inputIP;
cmd.Parameters.Add(param);
reader = cmd.ExecuteReader();
…
}
5
This is a sample exam only

a. (2 marks) The namespace System.Data.SqlClient is needed to compile the above
code. However, this namespace does not come pre-built with .NET Core framework.
What will you do to resolve this issue?
According to (Lutz & Laplante, 2013), you add the reference needed using the reference
manager in the visual studio.
b. (2 marks) What is the special name for the type of SQL code used in Box A? What
advantage does its use offer?
SQL query
Advantage – According to (Sanderson, S. 2011), the sql query is used to retrieve large
data with a convenient time from the database.
c. (6 marks) What is happening in Box B? Explain the code line by line in your own words.
SqlParameter param = new SqlParameter(); - this is the declaration of
parameter object.
param.ParameterName = "@IP"; - definition of a SqlParameter
instance for each parameter in the SqlCommand object’s SQL command.
param.SqlDbType = SqlDbType.VarChar;- defining the data type for the
parameter.
param.Size = 15; - defining the maximum length of a request that is sent to a URL.
param.Direction = ParameterDirection.Input; - this sets a value that
indicates that the parameter is input-only.
param.Value = inputIP; - this allocates the value of the variable bound to the
parameter.
6
This is a sample exam only
code. However, this namespace does not come pre-built with .NET Core framework.
What will you do to resolve this issue?
According to (Lutz & Laplante, 2013), you add the reference needed using the reference
manager in the visual studio.
b. (2 marks) What is the special name for the type of SQL code used in Box A? What
advantage does its use offer?
SQL query
Advantage – According to (Sanderson, S. 2011), the sql query is used to retrieve large
data with a convenient time from the database.
c. (6 marks) What is happening in Box B? Explain the code line by line in your own words.
SqlParameter param = new SqlParameter(); - this is the declaration of
parameter object.
param.ParameterName = "@IP"; - definition of a SqlParameter
instance for each parameter in the SqlCommand object’s SQL command.
param.SqlDbType = SqlDbType.VarChar;- defining the data type for the
parameter.
param.Size = 15; - defining the maximum length of a request that is sent to a URL.
param.Direction = ParameterDirection.Input; - this sets a value that
indicates that the parameter is input-only.
param.Value = inputIP; - this allocates the value of the variable bound to the
parameter.
6
This is a sample exam only
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

7. (3 marks) Consider the following C# code snippet and answer the questions that follow:
class Program
{
static void Main(string[] args)
{
WishIAttendedTheLectures sigh = new
WishIAttendedTheLectures();
Console.WriteLine("4 + 2 = " + sigh.Add(4, 2));
Console.WriteLine("4 - 2 = " + sigh.Sub(4, 2));
}
}
public interface IMath
{
double Add(double x, double y);
double Sub(double x, double y);
}
class Math : IMath
{
public double Add(double x, double y) { return x + y; }
public double Sub(double x, double y) { return x - y; }
}
class WishIAttendedTheLectures : IMath
{
private Math _math = new Math();
public double Add(double x, double y)
{
return _math.Add(x, y);
}
public double Sub(double x, double y)
{
return _math.Sub(x, y);
}
}
Which pattern is being used in the code on page 7?
Abstract Factory pattern.
class Program
{
static void Main(string[] args)
{
WishIAttendedTheLectures sigh = new
WishIAttendedTheLectures();
Console.WriteLine("4 + 2 = " + sigh.Add(4, 2));
Console.WriteLine("4 - 2 = " + sigh.Sub(4, 2));
}
}
public interface IMath
{
double Add(double x, double y);
double Sub(double x, double y);
}
class Math : IMath
{
public double Add(double x, double y) { return x + y; }
public double Sub(double x, double y) { return x - y; }
}
class WishIAttendedTheLectures : IMath
{
private Math _math = new Math();
public double Add(double x, double y)
{
return _math.Add(x, y);
}
public double Sub(double x, double y)
{
return _math.Sub(x, y);
}
}
Which pattern is being used in the code on page 7?
Abstract Factory pattern.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

What advantages does its use offer? List any three.
It gives method to code for the interfaces than implementing.
It gets rid of the real implementations classes from the code of client.
It also ensures that code is easy to extent, (Thai & Lam, 2013).
PROCEED TO SECTION B
8
This is a sample exam only
It gives method to code for the interfaces than implementing.
It gets rid of the real implementations classes from the code of client.
It also ensures that code is easy to extent, (Thai & Lam, 2013).
PROCEED TO SECTION B
8
This is a sample exam only

Section B/ ASP.NET Core [50 marks]
8. (5 marks = 1 + 1 + 1 + 1 + 1) Complete the entries in Column B- one of them has been
completed for you:
Column A Column B
a. Data validation code is found in Model class/file.
b. Foreign key constraint
is found in Data set in mdf database.
c. Composite key constraint
is found in table of a sql server.
d. Route constraints at a global
level are found in Global.asax.file
e. Connection string to database
is found in Web.config file
f. Web server startup code
is found in web.xml file
9
This is a sample exam only
8. (5 marks = 1 + 1 + 1 + 1 + 1) Complete the entries in Column B- one of them has been
completed for you:
Column A Column B
a. Data validation code is found in Model class/file.
b. Foreign key constraint
is found in Data set in mdf database.
c. Composite key constraint
is found in table of a sql server.
d. Route constraints at a global
level are found in Global.asax.file
e. Connection string to database
is found in Web.config file
f. Web server startup code
is found in web.xml file
9
This is a sample exam only
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9. (5 marks = 1 + 1 + 1 + 1 + 1) Explain in a sentence or two, the following Entity
Framework (EF) Core queries, one of them has been explained for you:
EF Core Query Explanation
a. using (var context = new Loading all the data
BloggingContext()) from ‘Blogs’ table in
{ a database. This is
var blogs = equivalent to acontext.Blogs.ToList(); SELECT * FROM} sql query.
b. using (var context = new
BloggingContext())
Loading of list of
entities
{
var blog = context.Blogs
.Single(b => b.BlogId == 1);
}
c. var products = context.Prducts.Where
(p => p.CategoryId == 1 &&
p.UnitsInStock < 10);
Querying data using the
Dbset
d. var authors = context.Authors
.Include(a => a.Books) Loading related data
.ToList();
e. var cars = context.Cars
.AsNoTracking()
.ToList();
Updating many to many
relationship in Dbset
f. vat categories =
context.Categories.OrderBy(c =>
cCategoryName).ThenOrderBy(c =>
c.CategoryId);
Querying and sorting in
Dbset
Framework (EF) Core queries, one of them has been explained for you:
EF Core Query Explanation
a. using (var context = new Loading all the data
BloggingContext()) from ‘Blogs’ table in
{ a database. This is
var blogs = equivalent to acontext.Blogs.ToList(); SELECT * FROM} sql query.
b. using (var context = new
BloggingContext())
Loading of list of
entities
{
var blog = context.Blogs
.Single(b => b.BlogId == 1);
}
c. var products = context.Prducts.Where
(p => p.CategoryId == 1 &&
p.UnitsInStock < 10);
Querying data using the
Dbset
d. var authors = context.Authors
.Include(a => a.Books) Loading related data
.ToList();
e. var cars = context.Cars
.AsNoTracking()
.ToList();
Updating many to many
relationship in Dbset
f. vat categories =
context.Categories.OrderBy(c =>
cCategoryName).ThenOrderBy(c =>
c.CategoryId);
Querying and sorting in
Dbset
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

10. (10 marks) Answer the following questions:
a. (3 marks) List three ways of error handling in an ASP.NET Core project. There is no
need to write any code. Use of try-catch block is not an acceptable answer.
Configuring a customized exception handling page
Configuring status code pages
Troubleshooting ASP.NET core.
b. (7 marks) How can error pages be customised in an ASP.NET Core project? List the
steps. Why is this customisation needed?
Creating the controller classes
Creating the view for the index actions
Setting a middleware to handle the actions and requests in the line.
Setting up the startup classes in the configure method
11
This is a sample exam only
a. (3 marks) List three ways of error handling in an ASP.NET Core project. There is no
need to write any code. Use of try-catch block is not an acceptable answer.
Configuring a customized exception handling page
Configuring status code pages
Troubleshooting ASP.NET core.
b. (7 marks) How can error pages be customised in an ASP.NET Core project? List the
steps. Why is this customisation needed?
Creating the controller classes
Creating the view for the index actions
Setting a middleware to handle the actions and requests in the line.
Setting up the startup classes in the configure method
11
This is a sample exam only

11. (10 marks) Consider the following code snippet and answer the questions that follow:
@* The data refers to the ‘Student’ Model *@
<div>
@using (@Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table>
<tr>
<td>@Html.LabelFor(m => Model.RollNo)</td>
<td>@Html.TextBoxFor(m => Model.RollNo) </td>
</tr>
<tr>
<td>@Html.LabelFor(m => Model.Gender)</td>
<td>Male:@Html.RadioButtonFor(m => m.Gender,
"Male", new { @checked = "checked" })
Female:@Html.RadioButtonFor(m => m.Gender,
"Female", true)
</td>
</tr>
<tr>
<td><input type="submit" value="Submit" />
</td>
</tr>
</table>
}
</div>
a. (2 marks) Where are you most likely to find this code in an ASP.NET Core
project? (Model or View or Controller).
View
b. (2 marks) What will be the file extension of the file where you will find this code?
.aspx
12
This is a sample exam only
@* The data refers to the ‘Student’ Model *@
<div>
@using (@Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table>
<tr>
<td>@Html.LabelFor(m => Model.RollNo)</td>
<td>@Html.TextBoxFor(m => Model.RollNo) </td>
</tr>
<tr>
<td>@Html.LabelFor(m => Model.Gender)</td>
<td>Male:@Html.RadioButtonFor(m => m.Gender,
"Male", new { @checked = "checked" })
Female:@Html.RadioButtonFor(m => m.Gender,
"Female", true)
</td>
</tr>
<tr>
<td><input type="submit" value="Submit" />
</td>
</tr>
</table>
}
</div>
a. (2 marks) Where are you most likely to find this code in an ASP.NET Core
project? (Model or View or Controller).
View
b. (2 marks) What will be the file extension of the file where you will find this code?
.aspx
12
This is a sample exam only
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 19
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.