C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,822 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to create an array (only way to pass parameters to our data access component) but i dont know how many params i will need.
I have a bunch of bool variables and will add parameters if the bool is true
SqlParameter[] p = new SqlParameter[5];
if (IsCall)
p[0] = new SqlParameter("@IsCall", IsCall);
if (Given)
p[p.count] = new SqlParameter("@Given", Given);
Thanks !
If you cannot use a list, then consider this approach:
var list = new List<SqlParameter>( );
if( IsCall)
list.Add( new SqlParameter("@IsCall", IsCall));
if( Given)
list.Add( new SqlParameter("@Given", Given));
. . .
SqlParameter[ ] p = list.ToArray( );