|
AFAIK there isn't one. You can always create your own and use new a new Add method - something like
public class MyList<T> : List<T>
{
public new void Add(T item)
{
if (!Contains(item))
base.Add(item);
}
} You'll need to do something similar for AddRange, and keep track of any changing items to make sure they don't create duplicates.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
There is library available from Wintellect that has unordered set, the one you are looking for. You might try it if you wish.
|
|
|
|
|
It's worth remembering that there isn't a one-size-fits all algorithm to do stuff like this. The framework provides a set of general purpose collections and algorithms, but they might not be good enough in specific scenarios.
An unsorted list, which is what I understand you want, is going to be very slow at detecting duplicates. And its going to seriously degrade if you've got lots and lots of things in your collection. It might be worth running two data structures alongside each other to mitigate this.
So, roughly how many things are you going to insert into this? Is memory consumption an issue for you? Can we remove duplicates later on, or does it have to be done on insertion?
Regards,
Rob Philpott.
|
|
|
|
|
If you can use .NET 3.5, there is an HashSet class.
Otherwise, you have to build one, as others have said.
|
|
|
|
|
|
We have a WPF forum. Try to speak english, 'dat' is not a word, for example.
If your control is data bound using an observable collection, swapping the items in the collection, will swap them in the control.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Try not to delete questions, often people get referenced to these questions. Deleting them is pointless.
|
|
|
|
|
Please help
I am developing a CISCO IPPhone Solutions, and one of the feature is RTP streaming. As I search on the the web (including on CISCO) there is no any simple exmple how to implement this. However, on codeproject, I found one but seem like not match with my requirment. WinRTP should the correct solution, but I have no idea about it. Can any one englight me please.
Thank for advacned.
|
|
|
|
|
Dear All,
Our requirement is a cab has assigned to Pick and Drop the employee for each and every shifts for the selective date. So, we need to show how much distance a cab has travelled, then we need to show that cab has been assigned for Pick/Drop for all the selective date.
As per my Procedure we can get the "Shift Date Time", "Cab No", "Pick/Drop" value, etc....
In Range chart I need to show the "Shift Time" in "X Axis" like "9 AM", "10 AM", "11 AM".....upto Next day "8 AM".
then In "Y Axis" I need to show "Shift Date Time" & "Cab No." which come from table.
In "Y Axis" i can not show the "Shift Date Time", So, I tried to show in "X Axis", but I can show only shift Date not time.
Actually I need to show the shift date in "Y Axis" only.
If any one have the solution, Please reply me.
Thanks in Advance.
Regards,
Jegan.K
9994388922
Jegan
|
|
|
|
|
Hi!
I have ha promblem with adding items to a DataGridViewComboBoxCell. This is what I am doing.
private void SetUpforDataGridView()
{
dataGridViewSearched.ColumnCount = 5;
dataGridViewSearched.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy;
dataGridViewSearched.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
dataGridViewSearched.ColumnHeadersDefaultCellStyle.Font =
new Font(dataGridViewSearched.Font, FontStyle.Bold);
dataGridViewSearched.Name = "Users Searched";
dataGridViewSearched.AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
dataGridViewSearched.ColumnHeadersBorderStyle =
DataGridViewHeaderBorderStyle.Single;
dataGridViewSearched.CellBorderStyle = DataGridViewCellBorderStyle.Single;
dataGridViewSearched.GridColor = Color.Black;
dataGridViewSearched.RowHeadersVisible = false;
dataGridViewSearched.Dock = DockStyle.Fill;
DataGridViewComboBoxColumn dataGridViewcombobox = new DataGridViewComboBoxColumn();
dataGridViewSearched.Columns.Add(dataGridViewcombobox);
dataGridViewSearched.Columns[0].Name = "UserId";
dataGridViewSearched.Columns[1].Name = "Förnamn";
dataGridViewSearched.Columns[2].Name = "Efternamn";
dataGridViewSearched.Columns[3].Name = "Legitimation";
dataGridViewSearched.Columns[4].Name = "Yrkesroll";
dataGridViewSearched.Columns[5].Name = "Enheter";
dataGridViewSearched.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewSearched.Columns[0].Visible = false;
dataGridViewSearched.Columns[0].DefaultCellStyle.Font =
new Font(dataGridViewSearched.DefaultCellStyle.Font, FontStyle.Italic);
dataGridViewSearched.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;
dataGridViewSearched.MultiSelect = false;
}
And the I am trying to set the table with an object it works fine with the text propertis but not with the DataGridViewComboBoxCell.
public void BindUserList(List<User> userList)
{
dataGridViewSearched.Rows.Clear();
object[] row = new object[5];
foreach (User p in userList)
{
row[0] = p.UserId;
row[1] = p.FirstName;
row[2] = p.LastName;
row[3] = p.MedicalProfession;
row[4] = p.ProfessionalRole;
dataGridViewSearched.Rows.Add(row);
foreach (var unit in p.UnitActivationPeriods)
{
((DataGridViewComboBoxCell)dataGridViewSearched.Rows[dataGridViewSearched.Rows.Count - 1].Cells[5]).Items.Add(unit.ToString());
}
dataGridViewSearched.Rows[dataGridViewSearched.Rows.Count - 1].Tag = p;
}
labelNumberOfUsers.Text = userList.Count.ToString();
dataGridViewSearched.Refresh();
}
Thanks, Mjelten
modified on Tuesday, June 23, 2009 6:51 AM
|
|
|
|
|
Is there a better way to code the second foreach...?
bool blnAccepted = false;
IList<Country> ftList = svc.GetCountryList;
IList<County> CountyList = svc.GetCountyList;
foreach (Country c in ftList)
{
blnAccepted = false;
foreach (County ic in CountyList)
{
if (ic.County == c.County)
{
blnAccepted = true;
break;
}
}
if (blnAccepted)
{
}
}
|
|
|
|
|
Yes, I would imagine that creating a map of countries to counties would allow you to do a single lookup. I'm not sure I follow your overall logic, but if you're doing this second loop a lot, a lookup in a hashtable will make it quicker. That's assuming you need to lookup a county for a country. If you just want to see if it exists, then keep a sorted list, so you can perform a search on it, faster than looking through the whole list.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Use Contains method in of the list.
|
|
|
|
|
If you are using C# 3.X and above, you can use the extension methods of IEnumerable<t>; the one you are looking for is Intersect. So ftList.Intersect(CountyList) gives you a collection of all elements of ftList that are present in CountyList. Hope that helps!
|
|
|
|
|
How does this work for different classes? I simplified the code earlier, so this is what I have:
Table Def:
Locations: ID, Description, TypeID, ParentID
LocationType: TypeID, Description
Rows in Location:
1 England 1 0
2 France 1 0
3 London 2 1
4 Hampshire 2 1
5 Dorest 2 1
6 Portsmouth 3 4
6 Paris 2 2
etc....
Rows in LocationType:
1 Country
2 Regions
3 Cities
4 Hospitals
5 Hotels
I now have a hierarchy of locations, each with a specific type.
So how do I use ftList.Intersect(Type) on just the TypeID?
Foreach (ftList.Intersect(TypeID = 2 | 4 | 5 )) ???
|
|
|
|
|
For arbitrary filtering, use the Where extension method - you pass in a predicate to that method which can use any of the properties of your object.
|
|
|
|
|
I found that rewriting the SQL as a stored procedure was easier to get the hierarchy that I needed
CREATE PROC sp_Hierarchy
(@ParentID int)
AS
BEGIN
WITH _items(ID, ParentID, TypeID, Depth)
AS (
SELECT ID, ParentID, TypeID, 0 AS Depth FROM tblItems WHERE ID = @ParentID
UNION ALL
SELECT t.ID, t.ParentID, t.TypeID, i.Depth + 1 FROM tblItems t JOIN _item i ON t.ParentID = i.ID
)
SELECT * FROM _item
END
Just incase somebody else needed to know
|
|
|
|
|
I want to know whether my pc is using the UPS battery power??? Intention is, i want to know if any power failure happened...
Actually i think in laptop, they are using drivers to find it.... please give your ideas...
My small attempt...
|
|
|
|
|
|
Hi all,
i'm using webservice in my form, i called this service dynamicly according to its URL, i want to save its assemply localy to read it from any application rather than load this service everytime as any c# dll.
i use this code to load webservice but its a vb.net code
Dim Client As System.Net.WebClient = New System.Net.WebClient()
Dim Stream As System.IO.Stream
Dim Provider1 As CodeDomProvider
Dim oops As CompilerError
Dim assemblyReferences As String() = New String(4) {"System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll"}
Dim ComPram As CompilerParameters
Stream = Client.OpenRead(URL)
Dim Errors As String = ""
Dim Description As New ServiceDescription
Description = ServiceDescription.Read(Stream)
Dim Importer As ServiceDescriptionImporter = New ServiceDescriptionImporter()
Importer.AddServiceDescription(Description, String.Empty, String.Empty)
Importer.ProtocolName = "Soap"
Importer.Style = ServiceDescriptionImportStyle.Client
Importer.CodeGenerationOptions = Xml.Serialization.CodeGenerationOptions.GenerateProperties
Dim nmspace As CodeNamespace = New CodeNamespace()
Dim Unit1 As CodeCompileUnit = New CodeCompileUnit()
Unit1.Namespaces.Add(nmspace)
Dim Warning As ServiceDescriptionImportWarnings
Warning = Importer.Import(nmspace, Unit1)
If (Warning = 0) Then
Provider1 = CodeDomProvider.CreateProvider("VisualBasic")
ComPram = New CompilerParameters(assemblyReferences)
Result = Provider1.CompileAssemblyFromDom(ComPram, Unit1)
Thanks for help
|
|
|
|
|
If you're calling a webservice you won't have access to its compiled DLL, it is stored on the webserver.
|
|
|
|
|
hi
i want to authenticate active directory using C#.
i have used the method given at microsoft help and support but it isnt working
errors:
1.Error 1 'ASP.logon_aspx.GetTypeHashCode()': no suitable method found to override c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_e07ldux7.1.cs 822
2.Error 2 'ASP.logon_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_e07ldux7.1.cs 827
3.Error 3 'ASP.logon_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable' c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_e07ldux7.1.cs 205
they are beyond my understanding kindly help
plz its urgent!!!!!!
|
|
|
|
|
|
yeah that was exactly the link with whom i tried to implement the aforesaid task.
please note that this process at Microsoft support is giving a build time error in some file called
App_Web_zvun-gh2.1.cs
later part of that file is different every time.....
this file has lengthy coding of around 800-900 lines
the error shown is
Error 1 'ASP.logon_aspx.GetTypeHashCode()': no suitable method found to override c:\WINDOWS.0\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\formauthadcs\01297fec\b53d4630\App_Web_zvun-gh2.1.cs 822
i am completely unaware of the error and what it is trying to point to!!! ...so please
can anybody tell me for what it is suggesting????
|
|
|
|
|
The code provided in the link is working perfectly fine.
You only have to clear the Temp Files folder and rebuilding Web Site again. Hope this will solve the problem
himanshu
|
|
|
|