using System;
namespace delegete
{
delegate string change(string str);
class Replace
{
static string space(string s)
{
Console.WriteLine("Replacing spaces with hyphens");
return s.Replace(' ', '_');
}
static string word(string w)
{
Console.WriteLine("Replacing word is with at");
return w.Replace("is", "at");
}
static void Main(string[] args)
{
change ob = new change(space);
string S;
S = ob("This is the string");
Console.WriteLine("Resultant string--------->" + S);
ob = new change(word);
S = ob("This is the string");
Console.WriteLine("Replacing string--------->" + S);
Console.ReadLine();
}
}
}
Output

namespace delegete
{
delegate string change(string str);
class Replace
{
static string space(string s)
{
Console.WriteLine("Replacing spaces with hyphens");
return s.Replace(' ', '_');
}
static string word(string w)
{
Console.WriteLine("Replacing word is with at");
return w.Replace("is", "at");
}
static void Main(string[] args)
{
change ob = new change(space);
string S;
S = ob("This is the string");
Console.WriteLine("Resultant string--------->" + S);
ob = new change(word);
S = ob("This is the string");
Console.WriteLine("Replacing string--------->" + S);
Console.ReadLine();
}
}
}
Output
No comments:
Post a Comment