Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
Practical12_Delegate
{
public delegate string strDelegate(string
s);
public partial class Form1 : Form
{
strDelegate sd;
public Form1()
{
InitializeComponent();
}
private void btnUpper_Click(object
sender, EventArgs e)
{
sd = new
strDelegate(DelegateEx.AllChrUpperCase);
lblStr.Text=
sd.Invoke(txtStr.Text);
lblMsg.Text = "Upper Case . .
.";
}
private void btnLower_Click(object
sender, EventArgs e)
{
sd = new
strDelegate(DelegateEx.AllChrLowerCase);
lblStr.Text =
sd.Invoke(txtStr.Text);
lblMsg.Text = "Lower Case . .
.";
}
private void btnEncrypt_Click(object
sender, EventArgs e)
{
sd = new
strDelegate(DelegateEx.Encrypt);
lblStr.Text =
sd.Invoke(txtStr.Text);
lblMsg.Text = "Encrypted
string . . .";
}
private void btnReverse_Click(object
sender, EventArgs e)
{
sd = new
strDelegate(DelegateEx.StrReverse);
lblStr.Text =
sd.Invoke(txtStr.Text);
lblMsg.Text = "Reverse string
. . .";
}
private void btnRemSpace_Click(object
sender, EventArgs e)
{
sd = new
strDelegate(DelegateEx.StrRemoveSpace);
lblStr.Text =
sd.Invoke(txtStr.Text);
lblMsg.Text = "After removing
space . . .";
}
}
class DelegateEx
{
public static string
AllChrUpperCase(string s)
{
string upper = s.ToUpper();
return upper;
}
public static string
AllChrLowerCase(string s)
{
string lower = s.ToLower();
return lower;
}
public static string StrReverse(string s)
{
int len = s.Length;
char[] arr = new char[len];
for (int i = 0; i < len; i++)
{
arr[i] = s[len - 1 - i];
}
return new string(arr);
}
public static string Encrypt(string s)
{
int len=s.Length,i=0;
char[] str = new char[len];
string str1 = " ";
while (i < len)
{
if(String.Compare(
s[i].ToString(),str1)!=0)
str[i]=Convert.ToChar(Convert.ToInt32(s[i]) + 100);
else
str[i]= ' ';
i++;
}
return new string(str);
}
public static string
StrRemoveSpace(string s)
{
int len = s.Length, i = 0,j=0;
char[] str = new char[len];
string str1 = " ";
while (i < len)
{
//str[i] = ' ';
if (String.Compare(s[i].ToString(), str1) !=
0)
{ str[j] = s[i]; j++; }
i++;
}
return new string(str);
}
}
}
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM