Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
60 views

C Sharp File

The document discusses .NET framework and its key components. The .NET framework is a software development platform developed by Microsoft that allows creation of applications for the Windows platform. It supports languages like C# and VB.NET. The architecture is based on the Common Language Runtime (CLR) which is the execution platform, and class libraries which provide common functions. The CLR provides features like exception handling and garbage collection.

Uploaded by

Aditya Mergoju
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

C Sharp File

The document discusses .NET framework and its key components. The .NET framework is a software development platform developed by Microsoft that allows creation of applications for the Windows platform. It supports languages like C# and VB.NET. The architecture is based on the Common Language Runtime (CLR) which is the execution platform, and class libraries which provide common functions. The CLR provides features like exception handling and garbage collection.

Uploaded by

Aditya Mergoju
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Console Application

Ques 1. Write a Program in C# to Check whether a number is Palindrome or


not.

Ans.

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PalindromeNumber
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number : ");
int n = int.Parse(Console.ReadLine());
int k = n;
int r, s=0;
while (n > 0)
{
r = n % 10;
s = s*10 + r;
n = n / 10;
}
if (k == s)
{
Console.WriteLine("Number is Palindrome");
}
else
{
Console.WriteLine("Number is not Palindrome");
}
Console.ReadKey();
}
}
}
Ques 2. Write a Program in C# to demonstrate Command line arguments
Processing.

Ans.

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommandLineArgument
{
class Program
{
static void Main(string[] args)
{
//Command Line Argument Passing
/*
If you want to Pass Argumnets through Command Line then you can follow
these steps.
a-> Right Click on Project from Solution Explorer and Select Properties.
b-> In the Project Properties Windows, Navigate to “Debug Tab”
c-> You will Find the a text box “Command Line”
Here you can type the command line with separated by Space in the given
Dialog Box.
*/
//Iterate through Each Arguments passed
for(int i = 0; i < args.Length; i++)
{
Console.Write(args[i] + " ");
}
Console.WriteLine("Thank you for using Command Line Arguments.");
Console.ReadKey();
}
}
}
Ques 3. Write a Program in C# to find the roots of Quadratic Equation.

Ans.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QuadraticEquationRoot
{
class Program
{
static void Main(string[] args)
{
int a, b, c;
double d, x1, x2;
Console.WriteLine("Enter value of a: ");
a = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter value of b: ");


b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value of c: ");
c = Convert.ToInt32(Console.ReadLine());
d = b * b - 4 * a * c;
if(d == 0)
{
x1 = -b / (2 * a);
x2 = x1;
Console.WriteLine("Value of roots are : {0} and {1}", x1, x2);
}else if (d < 0)
{
Console.WriteLine("Roots are Imaginary.");
}
else
{
x1 = (-b + Math.Sqrt(d)) / (2 * a);
x2 = (-b - Math.Sqrt(d)) / (2 * a);
Console.WriteLine("Roots are {0} and {1}.", x1, x2);
}
Console.ReadKey();
}
}
}
Object Oriented Programming
Ques 1. To study class object and properties in C# .Net.

Ans. C# is based on the C++ programming language. Hence, the C# programming language
has in-built support for classes and objects. A class is nothing but an encapsulation of
properties and methods that are used to represent a real-time entity.

C# Class :-

In C#, class is a group of similar objects. It is a template from which objects are created. It
can have fields, methods, constructors etc.

Let's see an example of C# class that has two fields only.

public class Student


{
int id;//field or data member
String name;//field or data member
}

C# Object :-

In C#, Object is a real world entity, for example, chair, car, pen, mobile, laptop etc. In other
words, object is an entity that has state and behavior. Here, state means data and behavior
means functionality. Object is a runtime entity, it is created at runtime. Object is an instance
of a class. All the members of the class can be accessed through object.

Let's see an example to create object using new keyword.


Student s1 = new Student();//creating an object of Student

Example of Class and Object both:--

using System;
public class Student
{
int id;//data member (also instance variable)
String name;//data member(also instance variable)

public static void Main(string[] args)


{
Student s1 = new Student();//creating an object of Student
s1.id = 105;
s1.name = "Mohit Kumar";
Console.WriteLine(s1.id);
Console.WriteLine(s1.name);
}
}

Output:-

105

Mohit Kumar
Ques 2. Write a program to demonstrate Operator overloading.
Ans.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OveratorOverloading
{
/*
Overloaded operators are functions with special names the keyword operator
followed
by the symbol for the operator being defined. Similar to any other function,
an
overloaded operator has a return type and a parameter list.C# allows user-
defined
types to overload operators by defining static member functions using the
operator keyword.
*/
/*
access_specifier className operator Operator_symbol (parameters)
{
// Code
}
*/
class House
{
private double length;
private double bredth;
private double height;
public House()
{
length = 0.0;
bredth = 0.0;
height = 0.0;
}
public House(double l,double b, double h)
{
length = l;
bredth = b;
height = h;
}
public double Volume()
{
return length * bredth * height;
}
public static House operator +(House a, House b)
{
House h = new House();
h.length = a.length + b.length;
h.bredth = a.bredth + b.bredth;
h.height = a.height + b.height;
return h;
}
}
class Program
{
static void Main(string[] args)
{
House h1 = new House(10.2, 20, 2.5);
House h2 = new House(21.1, 21, 30.5);
House h3 = h1 + h2;
double h3Volume = h3.Volume();
Console.WriteLine("Volume of House: {0}", h3Volume);
Console.ReadKey();
}
}
}
Component Object Model Programming

Ques 1. Study of .NET Framework

Ans. The .Net framework is a software development platform developed by Microsoft. The
framework was meant to create applications, which would run on the Windows Platform.
The first version of the .Net framework was released in the year 2002.

The version was called .Net framework 1.0. The .Net framework has come a long way since
then, and the current version is 4.7.1.

The .Net framework can be used to create both - Form-based and Web-
based applications. Web services can also be developed using the .Net framework.

The framework also supports various programming languages such as Visual Basic and C#.
So developers can choose and select the language to develop the required application.

.Net Framework Architecture

The basic architecture of the .Net framework is as shown below.

.NET Components

The architecture of the .Net framework is based on the following key components;

1. Common Language Runtime


The "Common Language Infrastructure" or CLI is a platform on which the .Net programs
are executed.

 Exception Handling - Exceptions are errors which occur when the application is
executed.

Examples of exceptions are:

o If an application tries to open a file on the local machine, but the file is not
present.
o If the application tries to fetch some records from a database, but the
connection to the database is not valid.
 Garbage Collection - Garbage collection is the process of removing unwanted resources
when they are no longer required.

2. Class Library

The .NET Framework includes a set of standard class libraries. A class library is a collection
of methods and functions that can be used for the core purpose.

For example, there is a class library with methods to handle all file-level operations. So there
is a method which can be used to read the text from a file. Similarly, there is a method to
write text to a file.

3. Languages

The types of applications that can be built in the .Net framework is classified broadly into
the following categories.

 WinForms – This is used for developing Forms-based applications, which would run
on an end user machine. Notepad is an example of a client-based application.
 ASP.Net – This is used for developing web-based applications, which are made to run
on any browser such as Internet Explorer, Chrome or Firefox.
 ADO.Net – This technology is used to develop applications to interact with Databases
such as Oracle or Microsoft SQL Server.

.Net Framework Design Principle

The following design principles of the .Net framework is what makes it very relevant to
create .Net based applications.

1. Interoperability - The .Net framework provides a lot of backward support. Suppose if


you had an application built on an older version of the .Net framework, say 2.0. And
if you tried to run the same application on a machine which had the higher version of
the .Net framework, say 3.5. The application would still work. This is because with
every release, Microsoft ensures that older framework versions gel well with the latest
version.
2. Portability- Applications built on the .Net framework can be made to work on any
Windows platform. And now in recent times, Microsoft is also envisioning to make
Microsoft products work on other platforms, such as iOS and Linux.
3. Security - The .NET Framework has a good security mechanism. The inbuilt security
mechanism helps in both validation and verification of applications. Every
application can explicitly define their security mechanism. Each security mechanism
is used to grant the user access to the code or to the running program.
4. Memory management - The Common Language runtime does all the work or memory
management. The .Net framework has all the capability to see those resources, which
are not used by a running program. It would then release those resources accordingly.
This is done via a program called the "Garbage Collector" which runs as part of the
.Net framework.

The garbage collector runs at regular intervals and keeps on checking which system
resources are not utilized, and frees them accordingly.

5. Simplified deployment - The .Net framework also have tools, which can be used to
package applications built on the .Net framework.
Ques 2. Design Login form and create windows form using basic form controls
application.

Ans. Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoginForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String username = textBox1.Text;
String password = textBox2.Text;
MessageBox.Show("Your username is " + username + "and Password is : " +
password);
}
private void linkLabel1_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show("You can request here for changing password.");
}
private void linkLabel2_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show("You can create a new account here.");
}
}
}
Output :-

You might also like