Blue Marble Smartware .Net Fresher Interview Questions with Answers

Hi everyone, in this post we are going to discuss Blue Marble Smartware Interview Questions. These interview questions were asked during .NET fresher interviews. Let us discuss the answers for the questions briefly in this post;

1.What is the difference between structure and class in .net?

Some basic differences between structure and class are as follows:
i]Structures are value types and the classes are reference types.
ii]Classes are usually used for large amounts of data, whereas structs are usually used for smaller amounts of data.
iii]Classes can be inherited whereas structures not.
iv]A structure couldn’t be null like a class.
v]A structure couldn’t have a destructor such as a class.
vi]A structure can’t be abstract, a class can.

2. Explain SQL joins in .net:

As the name itself defines it is used to combine data or rows from two or more tables as per common field between them. The basic types of Joins are as follows-
i]INNER JOIN: It is the simplest join used. The INNER JOIN keyword selects all rows from both the tables as long as the condition satisfies.

ii]LEFT JOIN: This join also known as LEFT OUTER JOIN, returns all the rows of the table on the left side of the join and matching rows for the table on the right side of join.

iii]RIGHT JOIN: This join also known as RIGHT OUTER JOIN, returns all the rows of the table on the right side of the join and matching rows for the table on the left side of join.

iv]FULL JOIN: FULL JOIN creates the result-set by combining result of both LEFT JOIN and RIGHT JOIN. The result-set will contain all the rows from both the tables.

3. Explain inheritance with a sample program.

Inheritance is a concept of deriving a new class from the existing class. Derived class gets all the features from base clas with its own added-on features.
There are mainly four types of inheritance:
a) Single level inheritance
b) Multi-level inheritance
c) Hierarchical inheritance
d) Hybrid inheritance

SAMPLE CODE-
using System;
namespace InheritanceApplication {
class Shape {
public void setWidth(int w) {
width = w;
}
public void setHeight(int h) {
height = h;
}
protected int width;
protected int height;
}

// Derived class
class Rectangle: Shape {
public int getArea() {
return (width * height);
}
}
class RectangleTester {
static void Main(string[] args) {
Rectangle Rect = new Rectangle();

Rect.setWidth(5);
Rect.setHeight(7);

// Print the area of the object.
Console.WriteLine(“Total area: {0}”, Rect.getArea());
Console.ReadKey();
}
}
}
SAMPLE OUTPUT-
Total area: 35

4.What is an abstract class, Explain it with an example.

An abstract class is used to define the base class, which has the most basic definition of a particular requirement.An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share.

SAMPLE CODE-
using System;
public abstract class Vehicle {
public abstract void display();
}

public class Bus : Vehicle {
public override void display() {
Console.WriteLine(“Bus”);
}
}

public class Car : Vehicle {
public override void display() {
Console.WriteLine(“Car”);
}
}

public class Motorcycle : Vehicle {
public override void display() {
Console.WriteLine(“Motorcycle”);
}
}

public class MyClass {
public static void Main() {
Vehicle v;
v = new Bus();
v.display();
v = new Car();
v.display();
v = new Motorcycle();
v.display();
}
}

SAMPLE OUTPUT-
Bus
Car
Motorcycle

5. What is the use of Interface and how it is used.

An interface is important in C# because the language doesn’t support multiple inheritance of classes. For that, you must use an interface if you want to simulate inheritance for structs, because they can’t actually inherit from another struct or class.
Purposes of Interfaces are;
-create loosely coupled software
-support design by contract (an implementor must provide the entire interface)
-allow for pluggable software
-allow different objects to interact easily
-hide implementation details of classes from each other
-facilitate reuse of software

You can define an interface by using the interface keyword. as the following example shows.
interface IEquatable<T>
{
bool Equals(T obj);
}

6. What is SQL data reader and SQL adapter in .net?

SQL DATA READER:

SqlDataReader Object provides a connection oriented data access to the SQL Server data Sources from C# applications. ExecuteReader() in the SqlCommand Object sends the SQL statements to the SqlConnection Object and populate a SqlDataReader Object based on the SQL statement or Stored Procedures.
           SqlDataReader sqlReader = sqlCmd.ExecuteReader();
The SqlDataReader returns data via a sequential stream. To read this data, you must pull data from a table row-by-row Once a row has been read, the previous row is no longer available. To read that row again, you would have to create a new instance of the SqlDataReader and read through the data stream again.
          SqlDataReader.Read()

SQL DATA ADAPTER:

SqlDataAdapter Class is a part of the C# ADO.NET Data Provider and it resides in the System.Data.SqlClient namespace. SqlDataAdapter provides the communication between the Dataset and the SQL database. We can use SqlDataAdapter Object in combination with Dataset Object. DataAdapter provides this combination by mapping Fill method, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet.                                                               SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.Fill(ds);
The SqlDataAdapter Object and DataSet objects are combine to perform both data access and data manipulation operations in the SQL Server Database. When the user perform the SQL operations like Select , Insert etc. in the data containing in the Dataset Object , it won’t directly affect the Database, until the user invoke the Update method in the SqlDataAdapter.

REFERENCES:

https://stackoverflow.com/questions/13049/whats-the-difference-between-struct-and-class-in-net
https://www.geeksforgeeks.org/sql-join-set-1-inner-left-right-and-full-joins/
http://www.dotnetfunda.com/articles/show/3502/understanding-the-csharp-concepts-through-real-time-examples
https://www.tutorialspoint.com/csharp/csharp_inheritance.htm
https://www.codeproject.com/Questions/392978/what-is-Interface-in-Csharp-and-why-we-are-using-i
http://csharp.net-informations.com/data-providers/csharp-sqldataReader.htm