Jose Saiz

Jose Saiz

  • 1.4k
  • 243
  • 98.7k

class parameters by Ref

Jul 24 2019 5:58 PM
I need direction on HOW TO create class in C# that accept parameters by reference,
I am a bit confused with tutorial
 
https://www.tutorialspoint.com/csharp/csharp_reference_parameters
 
Back in time Visual Basic I used to create class/functions that accept parameters by Value and by Reference.
 
ByVal parameter needs to be passed with some value
 
ByRef parameter needs may be empty or has value
  1. //- Let's assume this my function   
  2. public string MyObject(int pParamValue1, ref string pParamValue2)   
  3. {  
  4.      string ResultValue = "Your Result value is";  
  5.      ResultValue += pParamValue1.ToString();  
  6.      if (pParamValue2 != null)  
  7.       {  
  8.          ResultValue += " By Reference: " + pParamValue;   
  9.       }   
  10.      return  ResultValue;  
  11. }   
  12. //- Using the function passing the parameter by value  
  13. string GetResult =  MyObject(20);        
  14.    
  15. //- Using the function passing the parameter by value and parameter by Ref.  
  16. string GetResult = MyObject(20,"Hello World");  
Am I in the right path?
 
Thanks

Answers (2)