PC Review


Reply
Thread Tools Rate Thread

C# Array question

 
 
Jason Huang
Guest
Posts: n/a
 
      28th Dec 2006
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      28th Dec 2006
Jason Huang wrote:
> 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
 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      28th Dec 2006
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!");

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

"Jason Huang" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Fabrizio Romano
Guest
Posts: n/a
 
      28th Dec 2006
Maybe a HashTable?
A HashTable represents a collection of key/value pairs.

Cheers
Fabrizio

"Jason Huang" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      28th Dec 2006
How about List<String, SqlParameter> .. ?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"Jason Huang" wrote:

> 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
>
>
>

 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      28th Dec 2006
Hi Peter,

I think you mean Dictionary<string, SqlParameter>?

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

"Peter Bromberg [C# MVP]" <(E-Mail Removed)> wrote in
message news:0DBA0038-CD97-4133-80C9-(E-Mail Removed)...
> How about List<String, SqlParameter> .. ?
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
>
>
> "Jason Huang" wrote:
>
>> 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
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
another array question Robert Dieckmann Microsoft Excel Worksheet Functions 4 20th Jan 2007 02:08 AM
Array question Lee Microsoft Excel Programming 1 11th Dec 2003 08:01 PM
Array question Stuart Microsoft Excel Programming 1 6th Aug 2003 04:13 AM
Is this an array question? Stuart Microsoft Excel Programming 0 5th Aug 2003 08:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:24 AM.