Click here to Skip to main content
15,888,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working in C#, and I have created a DLL to contain a library of various math functions.
I also have an app that generates various math values that need to be passed to the DLL.
Rather than passing them one by one to the DLL, which is easy to do, Id rather populate a structure, or a class, in the app and then pass the struct or class to the DLL as one object. In other words, the app creates the values, places the values in the struct or class and then passes the object to the DLL as one object which could be used to populate a local class or struct in the DLL.
Can anyone help? Thanks in advance.

What I have tried:

I have tried in calling program:
public  class Paramiters
{

    public  double A1;
}

Paramiters Parms = new Paramiters();
Parms.A1 = 2.0;


			DllInfo dllinfo = new DllInfo();

			dllinfo.InitializeInfo(ref Paramiters Parms);

Generates Errors	CS0118	'Form1.Paramiters' is a type but is used like a variable	
Error	CS1003	Syntax error, ',' expected



in the DLL...
public  class DLLInfo
{
    public  double A;
}

DLLInfo dllinfo = new DLLInfo();
public void InitializeInfo(ref DLLInfo dllinfo)
{
             No Errors generated
}
Posted
Updated 27-Apr-19 7:01am

C#
dllinfo.InitializeInfo(ref Parms);

You only have to specify the parameter type when you declare a method, but not when you are calling it.
 
Share this answer
 
The definition of InitializeInfo requires a DLLInfo object as its parameter, but you are trying to pass a Paramiters object. Also it is not clear how you expect this to work, unless you are expecting every method to take exactly the same set of parameters.
 
Share this answer
 
Quote:
By default, all parameters are passed by value in C#. Parameters are only passed by reference if you explicitly include an out or ref modifier. However, you need to be aware that when the type of the parameter is a reference type, you’re passing a reference rather than an actual object. For more information, see my article on parameter passing and the C# Programmer’s Reference.

[Author: Jon Skeet]


Required reading.

Designing C# Software With Interfaces - Simple Talk[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900