Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TemplateInterfaceMethods
- {
- public class Program
- {
- static void Main(string[] args)
- {
- // Дефиниране на шаблонен метод (типизиран):
- void Swap<M>(ref M param1, ref M param2)
- {
- M temp;
- temp = param1;
- param1 = param2;
- param2 = temp;
- }
- // Извикване на метода с различни типове данни,
- // които стават известни едва след неговата дефиниция
- int x = 5;
- int y = 4;
- Console.WriteLine("Before Swap(): X=" + x + " Y=" + y);
- Swap<int>(ref x, ref y);
- Console.WriteLine("After Swap(): X=" + x + " Y=" + y);
- string a = "Stilyan";
- string b = "Remzi";
- Console.WriteLine("Before Swap(): A=" + a + " B=" + b);
- Swap<string>(ref a, ref b);
- Console.WriteLine("After Swap(): A=" + a + " B=" + b);
- bool bool1 = true;
- bool bool2 = false;
- Console.WriteLine("Before Swap(): bool1=" + bool1 + " bool2=" + bool2);
- Swap<bool>(ref bool1, ref bool2);
- Console.WriteLine("After Swap(): bool1=" + bool1 + " bool2=" + bool2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement