Hi,
Ive got a simple C# program which I am using to read and display a CSV file. Ive writen a C program to do some maths calculations. Im wondering if I can implement this into my C# program or if it must be coded in C#.
Thanks!
James.
Hi,
Ive got a simple C# program which I am using to read and display a CSV file. Ive writen a C program to do some maths calculations. Im wondering if I can implement this into my C# program or if it must be coded in C#.
Thanks!
James.
If the C code is compiled as a DLL with exported functions, you can use PInvoke functionality to call the C functions from C#.
Sure you can. Add it as a seperate project within your solution and reference it like a DLL.
Although it sounds like it might just be simpler to re-write the code in C# and add it to your solution...
He who asks is a fool for five minutes, but he who does not ask remains a fool forever.
The fool wonders, the wise man asks. - Benjamin Disraeli
There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz
Depending on what you're doing, summing up values or only doing calculations on values that match your criteria, C# may be able to do this for you a single nifty one-liner.
Not completely sure about aggregate's syntax, but pretty sure it's very similar. That particular LINQ query returns all even values to the second power.Code:IEnumerableCollectionWithValues.Where(x => x % 2 == 0).Aggregate(n => n*n);
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
As has already been said, P/Invoke is a nifty way of achieving exactly what you want. Here some interesting background documentation: http://msdn.microsoft.com/en-us/magazine/cc164123.aspx
However, if all your C code is doing is some Math, it would make better sense to port the code to C#.