C Sharp File
C Sharp File
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());
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.
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.
using System;
public class Student
{
int id;//data member (also instance variable)
String name;//data member(also instance variable)
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
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 Components
The architecture of the .Net framework is based on the following key components;
Exception Handling - Exceptions are errors which occur when the application is
executed.
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.
The following design principles of the .Net framework is what makes it very relevant to
create .Net based applications.
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 :-