|
hi all i´m a little new in c# and i am having problem doing some programming
the question is: implement a method that returns an average of set variavel of arguments in integer type
can anyone help
it is quite simple but not for me
|
|
|
|
|
1. What do you mean by 'set' of arguments?
2. What kind of average? There is several differend kinds of average value...
|
|
|
|
|
So, let's say you have a set of an unknown number of arguments
void Test(params int[] arguments)
{
}
You could compute the average by using something like
int sum = 0;
foreach(int i in arguments)
{
sum += i;
}
int average = sum / arguments.Length;
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
To pass Variable Parameters to method use params keyword For example
public int GetAverage (params int[] nums)
{
}
MCAD
|
|
|
|
|
That looks very much like a school asignment. Are you trying to trick other people to do your homework?
---
b { font-weight: normal; }
|
|
|
|
|
Hi All,
This probably really easy for somebody out there but this problem is doing my head in! What i want to do is update a a single cell in a in a datarow of a datagrid with a value from a textbox so i don't have use a query to repopulate the datagrid after a update query.
What i've tried
Updating the DataTable or DataSet from the datagrid before updating with the following code:
1)mydatatable.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0);
2)ds.Tables[0].Columns[0].Table.Rows[lastUpdatedRecord].ItemArray.SetValue(int.Parse(txtVal.Text),0);
and then rebind it to the datagrid.
My problem is that the "ItemArray.SetValue" method doesn't seem to be updating the value when i check it through the step through debugging.
Please help,
Thanks in advance
confused
|
|
|
|
|
Dont play with the itemarry. It is handled internally.
mydatatable.Rows[lastUpdatedRecord] = int.Parse(txtVal.Text);
will do the job.
Live Life King Size
Alomgir Miah
|
|
|
|
|
Thank you for your response.
My problem is this:
mydatatable.Rows[lastUpdatedRecord] = "Needs Type DataRow"
DataRow is made up of a array of values, a single value in the array represents a single cell value in the datarow. I just need to update a single cell value in the datarow array.
Is there any other way of updating the datagrid without having to query the database?
Thanks in advance,
|
|
|
|
|
With just one indexer (lastUpdatedRecord ) you reference a single row, but when you use 2 indexers, you can access a single cell:
mydatatable.Rows[lastUpdatedRecord][columnNumber] = newValue;
Regards,
mav
|
|
|
|
|
Sorted...Thanks mav
Your A king!
|
|
|
|
|
Is there a CodeParser concrete class to parse C++ code?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
There are tools available. Look for programmar in google.
Live Life King Size
Alomgir Miah
|
|
|
|
|
None that I know of. I know for sure that the .NET Framework doesn't have one, but I'm not sure about the availability of 3rd party implementations.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Try www.antlr.org or www.devincook.com/goldparser.
|
|
|
|
|
I have successfully called a Fortran dll from unmanaged C++ and now I'm trying this in C#.
This is my attempt:
<br />
class MyClass {<br />
[DllImport(@"square.dll", EntryPoint="aFunc")]<br />
public static extern void aFunc(out int aNum);<br />
public static int Main() {<br />
int aNum=20;<br />
aFunc(out aNum);<br />
Console.WriteLine(aNum);<br />
return 0;<br />
}<br />
}<br />
The dll merely squares the number and sends it back out. The error message is System.DllNotFoundException. I think the reason is that I'm not able to add reference. It keeps saying that it's not a valid .COM or .dll !
Suggestions greatly welcomed.
Kash
|
|
|
|
|
You need to add the DLL path to the PATH environment variable or you can just copy the DLL in the same folder as your managed assemblies.
Live Life King Size
Alomgir Miah
|
|
|
|
|
I managed to get it to work by putting the .lib and .dll file in bin\Release folder but now I have some new problems.
This works to an extent.
The number goes in OK, and does the calc inside the dll correctly but the new number is not sent back. I tried both "out" and "ref" declarations.
class MyClass<br />
{<br />
[DllImport(@"square.dll", EntryPoint="aFunc")]<br />
<br />
public static extern void aFunc(float aNum);<br />
<br />
public static int Main() <br />
{<br />
float aNum=20.0F;<br />
aFunc(aNum);<br />
Console.WriteLine(aNum);<br />
return 0;<br />
}<br />
}<br />
}
|
|
|
|
|
Kash wrote:
public static extern void aFunc(float aNum);
Of course not. Since you've told C# that the return type for the funtion is void, it's not expecting any return value. What this code is supposed to look like depends heavily on what the function declaration in your C++ code looks like. Without knowing that...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The actual dll is written in Fortran and I performaed a test in C++ using a void function declaration and it worked. What I'm trying to do is do the same in C#. I'm very new to C#, sorry if this is basic.
I've tried putting the code in an unsafe context but still not returning xo althought both xi and xo (xi**2) in the dll are correct.
class MyClass<br />
{<br />
[DllImport(@"square.dll", EntryPoint="aFunc")]<br />
<br />
unsafe public static extern void aFunc(float xi, out float * xo);<br />
<br />
public static int Main() {<br />
float xi=20.0F;<br />
unsafe {<br />
float * xo;<br />
aFunc(xi,out xo);<br />
Console.WriteLine(*xo);<br />
}<br />
return 0;<br />
}<br />
}<br />
}
thanks in advance.
|
|
|
|
|
OK, now the function definition changed. You're no longer passing one parameter, but two.
One more time -> WITHOUT SEEING THE ORIGINAL FUNCTION DEFINITION, IT'S IMPOSSIBLE TO TELL YOU WHAT YOU'RE DOING WRONG!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
subroutine aFunc(xi,xo)
real , intent(in) :: xi
real , intent(out) :: xo
!
!DEC$ATTRIBUTES dllexport :: aFunc
!DEC$ATTRIBUTES DEFAULT,STDCALL, DECORATE, ALIAS: 'aFunc' :: aFunc
!
xo = xi*xi
end subroutine aFunc
|
|
|
|
|
I need help remotely connecting to a database. I have a workstation named EC-BJACOB with my database on it. I'm also running the SQL Server Manager (service: SQL Server) on that workstation. So far I've been coding my application on the same worktsation and have had no trouble connecting to the database to run my SQL queries against it.
The application is ready to be tested remotely, however, and I'm running into problems. When I run the application from my laptop comuter (which is joined to the same network), I get the following error:
Message: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
This is what my connection string looks like:
@"Integrated Security=SSPI;Packet Size=4096;Data Source=""EC-BJACOB"";Initial Catalog=BenefitSelectDBSQL;Provider=""SQLOLEDB"";Workstation ID=""EC-BJACOB"";Use Encryption for Data=False";
I'm new to C# and especially new to database programming, so I don't really know where to start to address this issue.
Thanks for any help you can give!
The ends can never justify the means. It is the means that determine the ends.
|
|
|
|
|
This is what the connection string really looks like:
@"Integrated Security=SSPI; Packet Size=4096;Data Source=""DB-NGIVENS"";Initial Catalog=BenefitSelectDBSQL; Provider=""SQLOLEDB"";Workstation ID=""DB-NGIVENS"";Use Encryption for Data=False";
The ends can never justify the means. It is the means that determine the ends.
|
|
|
|
|
You are using Integrated Security here. If this is a windows application, it's picking up your credentials from your network login; if it's a web application, it's picking up ASPNET's credential.
Make sure you [or ASPNET] have login rights to the database.
Personally when I'm stuck, I try 2 things: (1) I try going in to Query Analyzer and checking my integrated security credentials by logging in to the server in question; and (2) I try using a User Name and Password in my connection string to see if that makes any difference, instead of Integrated Security. You might have to be in mixed mode for that, though. More on that if you want it.
I hope that's a start for you.
|
|
|
|
|
That is a start, and I appreciate the reply, but the truth is I'm not really sure what Integrated Security is, or how I ended up using it. It is a windows application (not a web application).
I don't actually have a network login, that I know of. On the test computer I don't login to the network. I get onto the WLAN because I set up the wep key, and they haven't seperated the LAN from the WLAN, so I can get into the printers, server, etc. from there.
I'd be happy to change it to mixed mode and send a password, but I'm not sure how to do do that. I've also never used the Query Analyzer, but I'll try that out tomorrow.
So any further information you can give me will be MOST helpful.
Thanks again for the reply!
The ends can never justify the means. It is the means that determine the ends.
|
|
|
|