6

Passing an assembly value to an application in C #

 2 years ago
source link: https://www.codesd.com/item/passing-an-assembly-value-to-an-application-in-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Passing an assembly value to an application in C #

advertisements

If I have an assembly which contains a function that manipulates a string and then returns that string, and I then have a separate C# application which calls the function from the assembly...

How can I pass the manipulated string from the assembly into the application?

For example, If I have this assembly...

using System;

namespace test
{

    public class Class1
    {
        string inputString = "hello";
        string outputString;

        public static string Convert(ref inputString, ref outputString)
        {
            outputString = inputString.ToUpper();
            return outputString;
        }
    }
}

And I have this application which calls the Convert function within the assembly...

using System;
using test;

public class Class2
{
    public static void Main()
    {
        Class1.Convert();
    }
}

How can I get the returned outputString into the Class2 application? I can't reference it in the Main() function so how can I pass it in?


It looks like you want to pass in a valid and then return another value? Then get rid of the of properties on your Class1, they are not necessary. Just make the input string the parameter of the Convert function, and then return the output.

using System;

namespace test
{

    public class Class1
    {
        public static string Convert(string inputString)
        {
            string outputString = inputString.ToUpper();
            return outputString;
        }
    }
}

using System;
using test;

public class Class2
{
    public static void Main()
    {
        string thisIsMyReturnedString = Class1.Convert("whatever the input value should be");
    }
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK