Click here to Skip to main content
15,889,865 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why Does by-value-passing object change? Pin
Russell Jones10-Apr-07 21:41
Russell Jones10-Apr-07 21:41 
QuestionHow to Export Gridview to Exel sheet in C#.net Pin
sundeeppatil10-Apr-07 11:13
sundeeppatil10-Apr-07 11:13 
QuestionHow to discard invalid (ASCII 0-32) user input in editbox? [modified] Pin
SandeepN10-Apr-07 9:09
SandeepN10-Apr-07 9:09 
AnswerRe: How to discard invalid (ASCII 0-32) user input in editbox? Pin
kubben10-Apr-07 12:15
kubben10-Apr-07 12:15 
GeneralRe: How to discard invalid (ASCII 0-32) user input in editbox? [modified] Pin
SandeepN10-Apr-07 12:39
SandeepN10-Apr-07 12:39 
QuestionXslCompiledTransform.Transform() to a string Pin
eggie510-Apr-07 8:56
eggie510-Apr-07 8:56 
AnswerRe: XslCompiledTransform.Transform() to a string Pin
eggie510-Apr-07 9:24
eggie510-Apr-07 9:24 
QuestionStoring references in a class Pin
Ephoy10-Apr-07 8:39
Ephoy10-Apr-07 8:39 
I have some modules which have to be able to take some input parameteres, process it and serve some output parameters. The modules are implemented as a class and the parameter (input or output) might have different types from module to module. The references is stored as Object. I have tried to make a simple test setting where I have some user input supplied to the first module and the output of the first module is the input of the second etc.
firstInput -> mod1 -> mod2 -> readOutput

I have some real problems because the reference (input of mod2) to the output of the the previous module (output of mod1) is lost after the constructer terminates. I would appreciate any help, even if the solution is to approach it with a new design.

The code I have come up with so far is this.
class module
{
    private object input; // use objects for reference
    public object output; // needs to be public to set up the reference in later modules. (I know its ugly/bad)

    public module(object source)
    {
        this.input = source; // save the reference to the source

        this.output = new int(); // create new instance for next module to reference
    }

    public void compute(int i)
    {
        this.output = (int)this.input + i;
    }

    public int getOutput()
    {
        return (int)this.output;
    }
}

class TestClass
{
    public static int test()
    {
        Object firstInput = (int)1;
        module mod1 = new module(firstInput);
        module mod2 = new module(mod1.output);
        mod1.compute(2);
        mod2.compute(3);
        int result = mod2.getOutput();
        return result; // result should be 6 but is 3
    }
}


-Lothver
AnswerRe: Storing references in a class Pin
Martin#10-Apr-07 9:11
Martin#10-Apr-07 9:11 
GeneralRe: Storing references in a class Pin
Ephoy10-Apr-07 10:09
Ephoy10-Apr-07 10:09 
GeneralRe: Storing references in a class [modified] Pin
Martin#11-Apr-07 3:11
Martin#11-Apr-07 3:11 
AnswerRe: Storing references in a class Pin
Scott Dorman10-Apr-07 17:48
professionalScott Dorman10-Apr-07 17:48 
GeneralRe: Storing references in a class Pin
Ephoy11-Apr-07 0:11
Ephoy11-Apr-07 0:11 
GeneralRe: Storing references in a class Pin
Scott Dorman12-Apr-07 2:53
professionalScott Dorman12-Apr-07 2:53 
Questionconvert grayscale array to Image Pin
aei_totten10-Apr-07 7:17
aei_totten10-Apr-07 7:17 
QuestionMDI application childform maximize Pin
sinosoidal10-Apr-07 6:33
sinosoidal10-Apr-07 6:33 
AnswerRe: MDI application childform maximize Pin
il_masacratore11-Apr-07 21:29
il_masacratore11-Apr-07 21:29 
QuestionString Manipulation Question Pin
JMOdom10-Apr-07 6:20
JMOdom10-Apr-07 6:20 
AnswerRe: String Manipulation Question Pin
Are Jay10-Apr-07 8:47
Are Jay10-Apr-07 8:47 
QuestionC# accessing Excel Pin
shamidi10-Apr-07 5:55
shamidi10-Apr-07 5:55 
AnswerRe: C# accessing Excel Pin
led mike10-Apr-07 7:39
led mike10-Apr-07 7:39 
QuestionFileWatcher Pin
LCI10-Apr-07 5:32
LCI10-Apr-07 5:32 
AnswerRe: FileWatcher Pin
vineas10-Apr-07 5:48
vineas10-Apr-07 5:48 
QuestionUser Control - comments for public properties in form designer Pin
peterchen10-Apr-07 5:13
peterchen10-Apr-07 5:13 
AnswerRe: User Control - comments for public properties in form designer Pin
Martin#10-Apr-07 5:40
Martin#10-Apr-07 5:40 

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.