C Sharp Lab
C Sharp Lab
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program1
{
static void Main(string[] args)
{
int x;
int a, b;
Console.WriteLine("Enter any two nymbers");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter your choice");
Console.WriteLine("1. Simple if statement");
Console.WriteLine("2. if else statement");
Console.WriteLine("3. else if statement");
Console.WriteLine("4. Exit");
x = Convert.ToInt32(Console.ReadLine());
switch (x)
{
case 1:
if (a < b)
{
Console.WriteLine("a is smallest");
}
break;
case 2:
if (a > b)
Console.WriteLine("a is largest");
else
Console.WriteLine("b is largest");
break;
case 3:
if (a == b)
Console.WriteLine("a is equal to b");
else if (a > b)
Console.WriteLine("a greater than b");
else
Console.WriteLine("b greater than a");
break;
case 4:
Console.WriteLine("Exit");
break;
default:
Console.WriteLine("invalid choice");
break;
}
Console.ReadKey();
}
}
}
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string gender, qualification;
if (radioButton1.Checked)
gender = "Male";
else
if (radioButton2.Checked)
gender = "FeMale";
else if (radioButton3.Checked)
gender = "Other";
else gender = "Gender not selected.";
if (checkBox1.Checked)
qualification = "Post Graduate";
else if (checkBox2.Checked)
qualification = "Graduate";
else if (checkBox3.Checked)
qualification = "PUC";
else qualification = "Not Checked";
MessageBox.Show("Name : " + textBox1.Text + "\nAddress : " +
textBox2.Text + "\nDOB :" + dateTimePicker1 + "\nGender : " +
gender + "\nState : " + comboBox1.Text + "\nQualification : " +
qualification);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApp4
{
class Program4
{
public static void method1()
{
// It prints numbers from 0 to 10
for (int I = 0; I <= 10; I++)
{
Console.WriteLine("Method1 is : {0}", I);
// When the value of I is equal to 5 then
// this method sleeps for 6 seconds
if (I == 5)
{
Thread.Sleep(6000);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace funsubdemo
{
class Program
{
//this is a subroutine
void AddValue(int a, int b)
{
Console.WriteLine("Value of a is: " + a);
Console.WriteLine("Value of b is: " + b);
//this is a method
int AddValues(int x, int y)
{
return x + y;
}
Console.ReadKey();
}
}
}
6. Application- BUILT IN FUN(vb.net)
MDI coding
Public Class Form2
End Sub
End Class
Child Class Coding
Public Class Form1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
void print(int i, int j)
{
Console.WriteLine("Printing int: {0}", (i + j));
}
void print(string a, string b)
{
Console.WriteLine("Printing String " + a + b);
}
static void Main(string[] args)
{
Program prog = new Program();
Console.WriteLine(descp);
Console.ReadKey();
}
}
Imports System.Data.OleDb
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles Button1.Click
Dim con As New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\indo\Desktop\rach-log\login.accdb")
Dim cmd As OleDbCommand = New OleDbCommand("select *
from table1 where username='" + TextBox1.Text & "' and
password='" + TextBox2.Text + "'", con)
con.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader
If dr.Read() = True Then
MsgBox("login success")
Else
MsgBox("invalid")
End If
End Sub
End Class
10. Windows application- database connectivity for core banking
transaction(vb.net)
Public Class Form1
End Sub
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button2.Click
BankBindingSource.EndEdit()
BankTableAdapter.Update(BanktransactionnewDataSet.bank)
MsgBox("Data has been saved")
SaveError:
Exit Sub
End Sub
End Sub
End Class
Part B
1. Prime using vb.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication22
{
public class PrimeNumber
{
public static void Main(string[] args)
{
int n, i, m = 0, flag = 0;
Console.Write("Enter the Number to check Prime: ");
n = int.Parse(Console.ReadLine());
m = n / 2;
for (i = 2; i <= m; i++)
{
if (n % i == 0)
{
Console.Write("Number is not Prime.");
flag = 1;
break;
}
}
if (flag == 0)
Console.Write("Number is Prime.");
Console.ReadKey();
}
}
}
4. Palindrome(C# -CONSOLE)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication22
{
public class Palindrome
{
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");
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication22
{
public class Sumdigit
{
public static void Main(string[] args)
{
int n, sum = 2, m;