By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,040 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Use CallByName in C#

P: 1
First add to referance Microsoft.VisualBasic

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Microsoft.VisualBasic;
  5. using Microsoft.VisualBasic.CompilerServices;
  6.  
  7. namespace CallByNameConsole
  8. {
  9.     class _TEST
  10.     {
  11.         private string _STR = "Called By The Name";
  12.  
  13.         public string _TESTSTR {
  14.             get {
  15.                 return _STR;
  16.             }
  17.             set {
  18.                 _STR = value;
  19.             }
  20.         }
  21.         public string _FUNCTION(int _X, int _Y) {
  22.             return (_X * _Y).ToString();
  23.         }
  24.         public void _PROCEDURE(int _X, int _Y) {
  25.             _Y *= _X;
  26.         }
  27.  
  28.     }
  29.     class Program
  30.     {        
  31.         static void Main(string[] args)
  32.         {
  33.             Console.Clear();
  34.  
  35.             _TEST _TESTER = new _TEST();
  36.  
  37.             string _STRING;
  38.  
  39.             _STRING = Versioned.CallByName(_TESTER, "_TESTSTR", CallType.Get).ToString();
  40.  
  41.             Console.WriteLine("Get _TESTSTR in _TEST : {0}",_STRING);
  42.  
  43.             Versioned.CallByName(_TESTER, "_TESTSTR", CallType.Set, "Changed By The CallByName");
  44.  
  45.             _STRING = Versioned.CallByName(_TESTER, "_TESTSTR", CallType.Get).ToString();
  46.  
  47.             Console.WriteLine("Set _TESTSTR in _TEST : {0}",_STRING);
  48.  
  49.             _STRING = (String)Versioned.CallByName(_TESTER, "_FUNCTION",CallType.Method, 2, 3);
  50.  
  51.             Console.WriteLine("Use _FUNCTION function in _TEST : {0}*{1}={2}",2,3,_STRING);
  52.  
  53.             int _A = 3, _B = 3;
  54.  
  55.             Versioned.CallByName(_TESTER, "_PROCEDURE", CallType.Method, _A, _B);
  56.  
  57.             Console.WriteLine("Use _PROCEDURE sub in _TEST {1}={0}*{1}",3,3,_A.ToString());
  58.  
  59.             Console.ReadLine();
  60.         }
  61.     }
  62. }
--------------------------------------------------------------------

Başak & Gökhan Tarhan

Software Development Specialists
Nov 26 '07 #1
Share this Article
Share on Google+