Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: Exception Handling / Response Question Pin
Eddy Vluggen20-Jun-14 9:21
professionalEddy Vluggen20-Jun-14 9:21 
GeneralRe: Exception Handling / Response Question Pin
Kevin Marois20-Jun-14 10:22
professionalKevin Marois20-Jun-14 10:22 
GeneralRe: Exception Handling / Response Question Pin
Eddy Vluggen20-Jun-14 11:05
professionalEddy Vluggen20-Jun-14 11:05 
QuestionPass specific object to a method expecting ref object parameter? Pin
arnold_w20-Jun-14 3:24
arnold_w20-Jun-14 3:24 
AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
Richard Deeming20-Jun-14 3:58
mveRichard Deeming20-Jun-14 3:58 
GeneralRe: Pass specific object to a method expecting ref object parameter? Pin
OriginalGriff20-Jun-14 3:59
mveOriginalGriff20-Jun-14 3:59 
GeneralRe: Pass specific object to a method expecting ref object parameter? Pin
Richard Deeming20-Jun-14 4:01
mveRichard Deeming20-Jun-14 4:01 
AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
OriginalGriff20-Jun-14 3:59
mveOriginalGriff20-Jun-14 3:59 
There is no "nice" way - ref parameters must be of the same exact type as the value being passed, and the value must be an assignable value, so casts aren;t allowed either. (This is to ensure type integrity: otherwise if you assigned a new instance of a class in the method, it could end up with a "bad" classSmile | :)
C#
class A {}
class B : A {}
class C : A {}
...
B b = new B();
Change(ref b);
// At this point, b contains an instance of C!
...
void Change(ref A a)
   {
   a = new C();
   }


You can do it, but you have to work with the system, and faff about a bit:
C#
public void Test()
    {
    string MyString = "";
    int MyInt = 0;
    object oS = MyString;
    GetTypeAndSetToOne(ref oS);
    MyString = (string) oS;
    object oI = MyInt;
    GetTypeAndSetToOne(ref oI);
    MyInt = (int) oI;
    }

Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
PIEBALDconsult20-Jun-14 7:41
mvePIEBALDconsult20-Jun-14 7:41 
AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
Eddy Vluggen20-Jun-14 8:47
professionalEddy Vluggen20-Jun-14 8:47 
Questionwhen using Stored Procedure called from C# ? Pin
Member 245846719-Jun-14 21:46
Member 245846719-Jun-14 21:46 
AnswerRe: when using Stored Procedure called from C# ? Pin
OriginalGriff19-Jun-14 22:21
mveOriginalGriff19-Jun-14 22:21 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846720-Jun-14 22:58
Member 245846720-Jun-14 22:58 
GeneralRe: when using Stored Procedure called from C# ? Pin
OriginalGriff20-Jun-14 23:22
mveOriginalGriff20-Jun-14 23:22 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846720-Jun-14 23:41
Member 245846720-Jun-14 23:41 
GeneralRe: when using Stored Procedure called from C# ? Pin
OriginalGriff21-Jun-14 0:06
mveOriginalGriff21-Jun-14 0:06 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846721-Jun-14 13:49
Member 245846721-Jun-14 13:49 
GeneralRe: when using Stored Procedure called from C# ? Pin
OriginalGriff21-Jun-14 19:43
mveOriginalGriff21-Jun-14 19:43 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846722-Jun-14 18:05
Member 245846722-Jun-14 18:05 
GeneralRe: when using Stored Procedure called from C# ? Pin
OriginalGriff22-Jun-14 18:48
mveOriginalGriff22-Jun-14 18:48 
AnswerRe: when using Stored Procedure called from C# ? Pin
Keith Barrow19-Jun-14 23:14
professionalKeith Barrow19-Jun-14 23:14 
AnswerRe: when using Stored Procedure called from C# ? Pin
Eddy Vluggen20-Jun-14 0:30
professionalEddy Vluggen20-Jun-14 0:30 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846721-Jun-14 14:02
Member 245846721-Jun-14 14:02 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846721-Jun-14 14:04
Member 245846721-Jun-14 14:04 
AnswerRe: when using Stored Procedure called from C# ? Pin
ZurdoDev20-Jun-14 2:01
professionalZurdoDev20-Jun-14 2:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.