Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views15 pages

Net Technology 2020 Question Solutions

networking question 2020 collection

Uploaded by

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

Net Technology 2020 Question Solutions

networking question 2020 collection

Uploaded by

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

.

net technology 2020 question solutions;

• Object-oriented languages follow all the concepts of OOPs whereas, the


object-based language doesn’t follow all the concepts of OOPs like
inheritance and polymorphism.
• Object-oriented languages do not have the inbuilt objects whereas Object-
based languages have the inbuilt objects, for example, JavaScript has
window object.
• Examples of object-oriented programming are Java, C#, Smalltalk, etc.
whereas the examples of object-based languages are JavaScript, VBScript,
etc.

Object Based Languages

• Object based languages supports the usage of object and


encapsulation.
• They does not support inheritance or, polymorphism or, both.
• Object based languages does not supports built-in objects.
• Javascript, VB are the examples of object bases languages.

Object Oriented Languages

• Object Oriented Languages supports all the features of Oops including


inheritance and polymorphism.
• They support built-in objects.
• C#, Java, VB. Net are the examples of object oriented languages.
What is .NET Framework
It is a virtual machine that provide a common platform to run an application that
was built using the different language such as C#, VB.NET, Visual Basic, etc. It is also
used to create a form based, console-based, mobile and web-based application or
services that are available in Microsoft environment. Furthermore, the .NET
framework is a pure object oriented, that similar to the Java language. But it is not a
platform independent as the Java. So, its application runs only to the windows
platform.

The main objective of this framework is to develop an application that can run on
the windows platform. The current version of the .Net framework is 4.8.

Components of .NET Framework


There are following components of .NET Framework:

1. CLR (Common Language Runtime)


2. CTS (Common Type System)
3. BCL (Base Class Library)
4. CLS (Common Language Specification)
5. FCL (Framework Class Library)
6. .NET Assemblies
7. XML Web Services
8. Window Services

CLR (common language runtime)

It is an important part of a .NET framework that works like a virtual component of


the .NET Framework to executes the different languages program like c#, Visual
Basic, etc. A CLR also helps to convert a source code into the byte code, and this
byte code is known as CIL (Common Intermediate Language) or MSIL (Microsoft
Intermediate Language). After converting into a byte code, a CLR uses a JIT compiler
at run time that helps to convert a CIL or MSIL code into the machine or native code.

CTS (Common Type System)

It specifies a standard that represent what type of data and value can be defined and
managed in computer memory at runtime. A CTS ensures that programming data
defined in various languages should beinteract with each other to share information.
For example, in C# we define data type as int, while in VB.NET we define integer as
a data type.

BCL (Base Class Library)

The base class library has a rich collection of libraries features and functions that
help to implement many programming languages in the .NET Framework, such as C
#, F #, Visual C ++, and more. Furthermore, BCL divides into two parts:

1. User defined class library


o Assemblies - It is the collection of small parts of deployment an application's
part. It contains either the DLL (Dynamic Link Library) or exe (Executable) file.
1. In LL, it uses code reusability, whereas in exe it contains only output
file/ or application.
2. DLL file can't be open, whereas exe file can be open.
3. DLL file can't be run individually, whereas in exe, it can run
individually.
4. In DLL file, there is no main method, whereas exe file has main
method.
2. Predefined class library
o Namespace - It is the collection of predefined class and method that present
in .Net. In other languages such as, C we used header files, in java we used
package similarly we used "using system" in .NET, where using is a keyword
and system is a namespace.
CLS (Common language Specification)

It is a subset of common type system (CTS) that defines a set of rules and regulations
which should be followed by every language that comes under the .net framework.
In other words, a CLS language should be cross-language integration or
interoperability. For example, in C# and VB.NET language, the C# language
terminate each statement with semicolon, whereas in VB.NET it is not end with
semicolon, and when these statements execute in .NET Framework, it provides a
common platform to interact and share information with each other.

Microsoft .NET Assemblies

A .NET assembly is the main building block of the .NET Framework. It is a small unit
of code that contains a logical compiled code in the Common Language
infrastructure (CLI), which is used for deployment, security and versioning. It defines
in two parts (process) DLL and library (exe) assemblies. When the .NET program is
compiled, it generates a metadata with Microsoft Intermediate Language, which is
stored in a file called Assembly.

FCL (Framework Class Library)

It provides the various system functionality in the .NET Framework, that includes
classes, interfaces and data types, etc. to create multiple functions and different
types of application such as desktop, web, mobile application, etc. In other words, it
can be defined as, it provides a base on which various applications, controls and
components are built in .NET Framework.

Key Components of FCL

1. Object type
2. Implementation of data structure
3. Base data types
4. Garbage collection
5. Security and database connectivity
6. Creating common platform for window and web-based application

Properties :
A property is a member that provides a flexible mechanism to read, write, or compute the
value of a private field. Properties can be used as if they're public data members, but
they're special methods called accessors. This feature enables data to be accessed easily
and still helps promote the safety and flexibility of methods.

Different between property and method:


• in general, methods represent actions and properties represent data.
Properties are meant to be used like fields, meaning that properties
should not be computationally complex or produce side effects.
When it does not violate the following guidelines, consider using a
property, rather than a method, because less experienced developers
find properties easier to use.
A method is a set of statements that is referred to by name and can
be called (invoked) at any point in a program simply by utilizing the
method’sname . Method take some input as parameters and return
the result as a return value.
A property is a member of a class which is used to set and get the
data from a data field of a class. A property is never used to store
data, it just acts as an interface to transfer the data. We use the
Properties as they are the public data members of a class, but they are
actually special methods called accessors.
A property is a member of a class which is used to set and get the data from
a data field of a class. A property is never used to store data, it just acts as
an interface to transfer the data. We use the Properties as they are the
public data members of a class, but they are actually special methods called
accessors.

A method is a set of statements that is referred to by name and can be


called (invoked) at any point in a program simply by utilizing the method’s
name.

Auto-implemented properties
In some cases, property get and set accessors just assign a value to or retrieve a
value from a backing field without including any extra logic. By using auto-
implemented properties, you can simplify your code while having the C# compiler
transparently provide the backing field for you.

If a property has both a get and a set (or a get and an init) accessor, both must be
auto-implemented. You define an auto-implemented property by using
the get and set keywords without providing any implementation. The following
example repeats the previous one, except that Name and Price are auto-
implemented properties. The example also removes the parameterized constructor,
so that SaleItem objects are now initialized with a call to the parameterless
constructor and an object initializer.

C#Copy
public class SaleItem
{
public string Name
{ get; set; }

public decimal Price


{ get; set; }
}

Generic means the general form, not specific. In C#, generic


means not specific to a particular data type.

C# allows you to define generic classes, interfaces, abstract


classes, fields, methods, static methods, properties, events,
delegates, and operators using the type parameter and without
the specific data type. A type parameter is a placeholder for a
particular type specified when creating an instance of the generic
type.

A generic type is declared by specifying a type parameter in an


angle brackets after a type name, e.g. TypeName<T> where T is a type
parameter.

Type of generic classes:

Generic Class
1. Generic classes are defined using a type parameter in an angle
brackets after the class name. The following defines a generic
class.

Example: Define Generic Class


class DataStore<T>
{
public T Data { get; set; }
}

You can also define multiple type parameters separated by a


comma.
Example: Generic Class with Multiple Type Parameters
class KeyValuePair<TKey, TValue>
{
public TKey Key { get; set; }
public TValue Value { get; set; }
}

Delegate:

C# delegates are similar to pointers to functions, in C or C++. A delegate is a


reference type variable that holds the reference to a method. The reference can be
changed at runtime.
Delegates are especially used for implementing events and the call-back methods.
All delegates are implicitly derived from the System.Delegate class.

Declaring Delegates
Delegate declaration determines the methods that can be referenced by the
delegate. A delegate can refer to a method, which has the same signature as that
of the delegate.
For example, consider a delegate −
public delegate int MyDelegate (string s);
The preceding delegate can be used to reference any method that has a
single string parameter and returns an int type variable.
Syntax for delegate declaration is −
delegate <return type> <delegate-name> <parameter list>
using System;

delegate int NumberChanger(int n);


namespace DelegateAppl {

class TestDelegate {
static int num = 10;

public static int AddNum(int p) {


num += p;
return num;
}
public static int getNum() {
return num;
}
static void Main(string[] args) {
//create delegate instances
NumberChanger nc1 = new NumberChanger(AddNum);

//calling the methods using the delegate objects


nc1(25);
Console.WriteLine("Value of Num: {0}", getNum());
Console.ReadKey();
}
}
}

C# Lambdas
Lambda expressions are how anonymous functions are created. In this article
and code examples, we will see how to implement lambdas in C#.

Lambda expressions are anonymous functions that contain expressions or


sequence of operators. All lambda expressions use the lambda operator =>,
that can be read as “goes to” or “becomes”. The left side of the lambda
operator specifies the input parameters and the right side holds an expression
or a code block that works with the entry parameters. Usually lambda
expressions are used as predicates or instead of delegates (a type that
references a method).
For example:
// example of lambda.
using System;
namespace demooflamda
{
class Program
{
delegate void mydelegate(string s);
static void Main(string[] args)
{
mydelegate d = x =>
{
Console.WriteLine(x);
};
d("hello World");
Console.ReadKey();
}
}
}

Lambda with two parameter


using System;
namespace demooflambda
{
delegate int product(int x, int y);
class Program
{
static void Main(string[] args)
{
product obj = (x, y) => x * y;
int result = obj(10, 20);
Console.WriteLine("product result is {0}", result);
Console.Read();
}
}
}

DOCTYPE html>
<html>

<head>
<title>User Reg.. Form</title>
</head>

<body>
<form method = "post" action = "">
<fieldset>
<legend>Add User</legend>
<div>
<label for = "UserName">User Name: </label>
<input type = "text" name = "UserName" value = "" />
</div>

<div>
<label for = "UserAdd">User Add:</label>
<input type = "text" name = "UserAdd" value = "" />
</div>

<div>
<label for = "Phone">Res. Phone:</label>
<input type = "text" name = "Phone" value = "" />
</div>
<div>
<label> </label>
<input type = "submit" value = "Submit" class = "submit" />
</div>
</fieldset>
</form>

</body>
</html>

Reading User Input from the Form


<!DOCTYPE html>
<html>

<head>
<title>Student Form</title>
</head>

<body>
@{
if (IsPost){
string StudentName = Request["StudentName"];
string UniName = Request["UniName"];
string Address = Request["Address"];

<p>
You entered: <br />
Student Name: @StudentName <br />
University Name: @UniName <br />
Res. Address: @Address <br />
</p>

namespace ErrorHandlingDemo
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
string connectionString =
ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
string selectSQL = "SELECT * FROM tblEmployees1";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "Employees");
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception ex)
{
// Log the exception
Label1.Text = "Something Bad happened, Please contact Administrator!!!!";
}
finally
{
}
}
}
}
}

Polymorphism can be static or dynamic. In static polymorphism, the response to a


function is determined at the compile time. In dynamic polymorphism, it is decided
at run-time.
Dynamic polymorphism is implemented by abstract classes and virtual functions.
The following is an example showing an example of dynamic polymorphism −

using System;

namespace PolymorphismApplication {
class Shape {
protected int width, height;

public Shape( int a = 0, int b = 0) {


width = a;
height = b;
}

public virtual int area() {


Console.WriteLine("Parent class area :");
return 0;
}
}

class Rectangle: Shape {


public Rectangle( int a = 0, int b = 0): base(a, b) {}

public override int area () {


Console.WriteLine("Rectangle class area :");
return (width * height);
}
}

class Caller {
public void CallArea(Shape sh) {
int a;
a = sh.area();
Console.WriteLine("Area: {0}", a);
}
}

class Tester {
static void Main(string[] args) {
Caller c = new Caller();
Rectangle r = new Rectangle(10, 7);
c.CallArea(r);
Console.ReadKey();
}
}
}

using System;
class Complex
{
private int x;
private int y;
public Complex()
}
public Complex(int i, int j)
{
x = i;
y = j;
}
public void ShowXY()
{
Console.WriteLine("{0} {1}", x, y);
}
public static Complex operator +(Complex c1, Complex c2)
{
Complex temp = new Complex();
temp.x = c1.x + c2.x;
temp.y = c1.y + c2.y;
return temp;
}
}
class MyClient
{
public static void Main()
{
Complex c1 = new Complex(10, 20);
Complex c2 = new Complex(20, 30);

Complex c3 = new Complex();


c3 = c1 + c2;
c3.ShowXY(); // dislplays 30 & 50
}
}
What is LINQ?
Language-Integrated Query (LINQ) is a powerful set of
technologies based on the integration of query capabilities directly
into the C# language. LINQ Queries are the first-class language
construct in C# .NET, just like classes, methods, events. The LINQ
provides a consistent query experience to query objects (LINQ to
Objects), relational databases (LINQ to SQL), and XML (LINQ to
XML).

using System.Data.Linq;

using System.Data.Linq.Mapping;

[Table(Name = "Employee.Employee")]

public class Employee

[Column]

public string ename;

[Column]

public string eaddress;

[Column]

public int salary;

private void LinqToSql_Load(object sender, EventArgs e)

// connection string

string connString = @"server = .\sql2012;integrated security = true;database =


dbemployee";

try

// Create data context


DataContext db = new DataContext(connString);

// Create typed table

Table<Employee> contacts = db.GetTable<Employee>();

// Query database

var employeeDetails =

from c in employee

select c;

// Display contact details

foreach (var c in employeeDetails)

txtLinqtoSql.AppendText(c.ename);

txtLinqtoSql.AppendText("\t");

txtLinqtoSql.AppendText(c.address);

txtLinqtoSql.AppendText("\t");

txtLinqtoSql.AppendText(c.salary);

txtLinqtoSql.AppendText("\n");

catch (Exception ex)

MessageBox.Show(ex.Message);

You might also like