C# Array question

  • Thread starter Thread starter Jason Huang
  • Start date Start date
J

Jason Huang

Hi,

In my C# windows form MyForm, I would like to have an array which is
[string, SqlParameter]
How do I declare this kind of array in C#?
Thanks for help.


Jason
 
Jason said:
In my C# windows form MyForm, I would like to have an array which is
[string, SqlParameter]
How do I declare this kind of array in C#?

If I have understood your question correctly, then you want
an array of either struct or class with those two members.

Arne
 
Hi Jason,

It's probably not a two-dimensional array that you need but an IDictionary
implementation instead. Anyway, object[,] can be used to declare a two
dimensional jagged array, however, you'll probably want a type-safe solution
regardless. You could use a generic Dictionary in the 2.0 framework
instead, or better yet, create a custom KeyedCollection implementation if
the "string" is actually supposed to represent the name of the SqlParameter
to which it's associated:

class KeyedSqlParameterCollection
: KeyedCollection<string, SqlParameter>
{
public KeyedSqlParameterCollection() { }

protected override string GetKeyForItem(SqlParameter parameter)
{
return parameter.ParameterName;
}
}

KeyedSqlParameterCollection parameters =
new KeyedSqlParameterCollection();

parameters.Add(new SqlParameter("name", "value"));

SqlParameter sqlParam = parameters["name"];

Debug.Assert((string) sqlParam.Value == "value", "Uh oh!");
 
Maybe a HashTable?
A HashTable represents a collection of key/value pairs.

Cheers
Fabrizio
 
Hi Peter,

I think you mean Dictionary<string, SqlParameter>? :)

--
Dave Sexton
http://davesexton.com/blog

Peter Bromberg said:
How about List<String, SqlParameter> .. ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Jason Huang said:
Hi,

In my C# windows form MyForm, I would like to have an array which is
[string, SqlParameter]
How do I declare this kind of array in C#?
Thanks for help.


Jason
 
Back
Top