How to use HashSet
-
Hi Experts, I am new to C#,I am trying to use
HashSet stringSet = new HashSet { "abc", "aa" };
Bu i am getting error as "A new expression requires () or [] after type" Whethier i should include any header file. Thanks Raj
-
Hi Experts, I am new to C#,I am trying to use
HashSet stringSet = new HashSet { "abc", "aa" };
Bu i am getting error as "A new expression requires () or [] after type" Whethier i should include any header file. Thanks Raj
try this: HashSet stringSet = new HashSet { "abc", "aa" } ;
-
Hi Experts, I am new to C#,I am trying to use
HashSet stringSet = new HashSet { "abc", "aa" };
Bu i am getting error as "A new expression requires () or [] after type" Whethier i should include any header file. Thanks Raj
HashSet<string> stringSet = new HashSet<string>() { "abc", "aa" };
foreach (string s in stringSet) log(s);works well on .NET 3.5 or 4.0 FWIW: the constructor parentheses are optional here! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
Hi Experts, I am new to C#,I am trying to use
HashSet stringSet = new HashSet { "abc", "aa" };
Bu i am getting error as "A new expression requires () or [] after type" Whethier i should include any header file. Thanks Raj
raju_shiva wrote:
Bu i am getting error as "A new expression requires () or [] after type"
Check answer at your previous question http://www.codeproject.com/Messages/3521515/Re-std-map-in-Csharp.aspx[^]
Knock out 't' from can't, you can if you think you can. :cool:
-
HashSet<string> stringSet = new HashSet<string>() { "abc", "aa" };
foreach (string s in stringSet) log(s);works well on .NET 3.5 or 4.0 FWIW: the constructor parentheses are optional here! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
Hi sir, I tried the above but i am getting error as "{ "abc", "aa" };" For this line ,its getting error
Error 1 ; expected E:\WindowsApplication1\WindowsApplication1\Form1.cs 66 63 WindowsApplication1
Error 2 ; expected E:\WindowsApplication1\WindowsApplication1\Form1.cs 66 70 WindowsApplication1
Error 3 Invalid expression term ',' E:\WindowsApplication1\WindowsApplication1\Form1.cs 66 70 WindowsApplication1
Error 4 ; expected E:\WindowsApplication1\WindowsApplication1\Form1.cs 66 72 WindowsApplication1
Error 5 ; expected E:\WindowsApplication1\WindowsApplication1\Form1.cs 66 77 WindowsApplication1 -
Hi Experts, I am new to C#,I am trying to use
HashSet stringSet = new HashSet { "abc", "aa" };
Bu i am getting error as "A new expression requires () or [] after type" Whethier i should include any header file. Thanks Raj
The collection initializer syntax "
new X { elements }
" is new in C# 3.0. The error message looks like you're using a C# 2.0 compiler (VS 2005?). You could rewrite this snippet to C# 2.0 by using explicit calls to Add(), but that still won't help you as theHashSet
class is new in .NET 3.5 as well.HashSet<string> stringSet = new HashSet<string>();
stringSet.Add("abc");
stringSet.Add("aa");