I am using VS 2008 and I need to know how to initialize the HashSet. I know Some values which is needed to add it during initialization. How can I add values to the tblNames.
System.Collections.Generic.HashSet<String[,]> tblNames;
tblNames = new System.Collections.Generic.HashSet<string[,]>();
tblNames.Add(new String[0,0] {"tblCategory","CatName" ,}); // this is showing Error..
The ultimate aim is to prevent user from entering duplicate values.I need to check it from different forms and from different tables and different fields.I go for querying the database using a dynamic query. I need to store the table name and column name in some index,value,value format for eg My tablename is tblCategory and field name is CatName
.So I will store the value in the way0,tblCategory,CatName
. So I will use Ajax to a handler page and in that I am using the above code.Here I am passing 0
to get the first value[tablename and column name]
,1 for another table and field and so on. So I thought of using this way.
Whether I am using the correct way or any other way to achieve the aim ie to prevent user from entering duplicate values ?
Thanks ,Harie
To initialize a Set with values, pass an iterable to the Set constructor. When an iterable is passed to the Set constructor, all elements get added to the new Set . The most common iterables to initialize a Set with are - array, string and another Set .
You can't.
A HashSet<T> object's capacity automatically increases as elements are added to the object. A HashSet<T> collection is not sorted and cannot contain duplicate elements. HashSet<T> provides many mathematical set operations, such as set addition (unions) and set subtraction.
If you want to initialize the HashSet
with a set of known values in one step, you can use code similar to the following:
HashSet<string[,]> tblNames;
string[,] stringOne = new string[1, 1];
string[,] stringTwo = new string[1, 1];
tblNames = new HashSet<string[,]> { stringOne, stringTwo };
This is called a collection initializer. It was introduced in C# 3.0, and includes the following elements:
{
and }
tokens and separated by commas.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With