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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

How array allocation is implemented in c#? 1
Readonly array elements 6
Array as little table 3
Large arrays in c# 9
CodeDom Question 1
JSON.Net 6
Shape Arrays VBA 0
initializing an array in C# 3

Back
Top