Gokaraju Rangaraju Institute of Engineering and Technology

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING AND

TECHNOLOGY
VISUAL PROGRAMMING USING C# AND .NET LAB

Course Code: L/T/P/C: 0/0/4/2


II Year II Semester

Course Objectives:
1. To provide hands on experience on .Net framework.
2. To appreciate the asynchronous event handling feature in .Net.
3. To offer end-to-end program model for web application development.
4. To develop applications for the .NET Framework using C#
5.To learn C# debugging techniques

Course Outcomes:
1. Create Event Driven Applications.
2. Develop asynchronous applications
3. Deploy Web services
4. Build database applications using ADO.NET
5. Understand the Language Integrated Query (Linq) library

TASK1: Write a program to check weather a given number is palindrome using C#.NET.
TASK2: Create a program to implement a concept of Overloading using C#.NET.
TASK3: Write a program to store the employee details using class and methods in C# .NET
TASK4: Create a program to implement the concepts of OOPS for creating class, inheritance
TASK5: Create a Window Form using HTML Controls
TASK6: Perform String Manipulation with the String Builder and String Classes and C#:
Demonstrates some basic string manipulation using both the String Builder and String
classes.
TASK7: Demonstrate the concept of
a) Creating a Thread
b) Managing a Thread
c) Deleting a Thread
TASK8: Create a Sample program to Demonstrate Insertion of data into database.
TASK9: Create a Program to Demonstrate Color Dialog in C#.
TASK10: Create a program to perform validation using validation controls.
TASK11: Create a Sample program to Demonstrate creation and usage of Dynamic Link
Libraries in C#.
TASK12: Student Management System application development with required details: Use
ADO.NET for storing and manipulating the data. Develop the necessary forms for the better
user interface.
TASK1: Write a program to check weather a given number is palindrome using
C#.NET.

STEP1: Create a new file in Visual studio code and save it as task1.cs

using System;
public class P
{
public static void Main (string [] args)
{
int n,r,sum=0,temp;
Console.Write("Enter the Number: ");
n = int.Parse(Console.ReadLine());
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
Console.Write("Number is Palindrome.");
else
Console.Write("Number is not Palindrome");
}
}

STEP2: Open new terminal and type command: csc task1.cs


STEP3: then type: .\task1
OUTPUT:
TASK2: Create a program to implement a concept of Overloading using C#.Net.

using System;  

public class Methodoverloading    


 {  
    public int add(int a, int b)  //two int type Parameters method  
  { 
int sum=a+b;
            return sum;      
  }  
    public double add(double a, double b,double c)  
  {  
        double sum=a+b+c;
        return sum;    
  
  }  
    public float add(float a, float b,float c,float d)  
  {  
        float sum=a+b+c+d;
        return sum;    
  
  }  
 
public static void Main(string[] args)
{
Methodoverloading ob=new Methodoverloading();

int sum2=ob.add(2,4);
Console.WriteLine("Sum of two integer value:"+sum2);

double sum3=ob.add(5.2d, 3.5d,3.2d);


Console.WriteLine("Sum of three double value:"+sum3);

float sum4=ob.add(0.1f,0.3f,0.8f,0.1f);
Console.WriteLine("Sum of four flat value:"+sum4);
}
}
OUTPUT:
TASK3: Write a program to store the employee details using class and methods in
C# .NET.

using System;

public class employee


{
    public int id;
    public string name;
    public float salary;
    public void insert(int i, string n, float s)
  {
        id=i;
        name=n;
        salary=s;
  }
    public void display()
  {
        Console.WriteLine(id+ " " +name+ " " +salary);

  }
}

class test
{
   public static void Main(string[] args)
  {
        employee e1 = new employee();
     
         int a;
         string b;
         float c;
         Console.WriteLine("Enter the No.");
         a=Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Enter name");
        b=Convert.ToString(Console.ReadLine());
         Console.WriteLine("Enter the salary.");
         c=Convert.ToInt32(Console.ReadLine());
         e1.insert(a,b,c);
     
         e1.display();
     

  }
}

STEP1: csc Employee.cs


STEP2: .\Employee.exe

OUTPUT:
TASK4: Create a program to implement the concepts of OOPS for creating class,
inheritance.

using System;
public class Employee
{
public float salary = 40000;
}
public class Programmer: Employee
{
public float bonus = 10000;
}
class TestInheritance{
public static void Main(string[] args)
{
Programmer p1 = new Programmer();

Console.WriteLine("Salary: " + p1.salary);


Console.WriteLine("Bonus: " + p1.bonus);

}
}

OUTPUT:
TASK5: Create a Window Form using HTML Controls

Step1: Check the dotnet version in the command Prompt by using below command
>dotnet –version
Step2: A new folder is to be created,
>dotnet new webapp -o MyWebApp --no-https -f net6.0
The dotnet new command creates a new application.

 The webApp parameter selects what template to use when creating your app.


 The -o parameter creates a directory named MyWebApp where your app is stored.
 The --no-https flag specifies not to enable HTTPS.
 The -f parameter indicates you're creating a .NET 6 application.

Several files were created in the MyWebApp directory to give you a simple web application
that is ready to run.

 Program.cs contains the app startup code and middleware configuration.


 The Pages directory contains some example web pages for the application.
 MyWebApp.csproj defines some project settings, such as, .NET SDK version to
target.
 The launchSettings.json file inside the Properties directory defines different profile
settings for the local development environment. A port number ranging between
5000-5300 is automatically assigned at project creation and saved on this file.

A new folder with name MyWebApp is created in C:\Users\visha\MyWebApp


Step3: MyWebApp PagesIndex(cshtml source file) in this notepad
Pages/Index.cshtml
@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h1>Hello, world!</h1>
    <p>The time on the server is @DateTime.Now</p>
</div>
Step4: again, goto cmd prompt and type commands:
cd MyWebApp
dotnet watch
Step5: A Output is displayed on the Window page(browser).

EXAMPLE PROGRAM

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with
ASP.NET Core</a></p>
    <head>
<title>Table</title>
</head>
<body>
<table border="1" width="200" height="200">
<caption>Invoice</caption>
<tr>
    <th>Sno</th>
    <th>Item</th>
    <th>Price</th>
</tr>
<tr>
    <td>1</td>
    <td>Apple</td>
    <td>Rs. 20</td>
</tr>
<tr>
    <td>2</td>
    <td>Mango</td>
    <td>Rs. 15</td>
</tr>
<tr>
    <td>3</td>
    <td>Banana</td>
    <td>Rs. 3</td>
</tr>
</table>
</body>
</div>
OUTPUT:
TASK6: Perform String Manipulation with the String Builder and String Classes and
C#: Demonstrates some basic string manipulation using both the String Builder and
String classes.

// C# program to demonstrate the


// difference between String,
// StringBuilder

using System;
using System.Text;
using System.Collections;
 
class stringbuilder {
    // Concatenates to String
    public static void concat1(String s1)
  {
 
        // taking a string which is to be Concatenated
        String st = "To C#.NET Lab";
 
        // using String.Concat method
        // you can also replace it with
        // s1 = s1 + "To C#.NET Lab";
        s1 = String.Concat(s1, st);
  }
 
    // Concatenates to StringBuilder
    public static void concat2(StringBuilder s2)
  {
 
        // using Append method of StringBuilder class
        s2.Append("To C#.NET Lab");
  }
 
    // Main Method
    public static void Main(String[] args)
  {
 
        String s1 = "Welcome";
        concat1(s1); // s1 is not changed
        Console.WriteLine("Using String Class: " + s1);
 
        StringBuilder s2 = new StringBuilder("Welcome");
        concat2(s2); // s2 is changed
        Console.WriteLine("Using StringBuilder Class: " + s2);
  }
}
OUTPUT:
TASK7: Demonstrate the concept of
a) Creating a Thread
b) Managing a Thread
c) Deleting a Thread

using System;
using System.Threading;
class Threading
{
    static void Main()
  {
        Thread thr=new Thread(mythread);
        Thread thr1=new Thread(mythread1);
        Console.WriteLine("thread started");
        thr.Start();
        thr1.Start();
//thr.Abort();
//thr1.Abort();
        Console.WriteLine("Thread ended");

  }

    static void mythread()


  {
        for(int i=0;i<=10;i++)
    {
            if(i%2==0 && i!=0)
            Console.WriteLine(i+ "evev");
            Thread.Sleep(1000);

    }
  }
static void mythread1()
  {
        for(int i=0;i<=10;i++)
    {
            if(i%2!=0 && i!=0)
            Console.WriteLine(i+ "Odd");
            Thread.Sleep(1000);

    }
  }
  
}
OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy