Remove value from geneic dictionary : Generic Dictionary « Generics « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net » Generics » Generic DictionaryScreenshots 
Remove value from geneic dictionary
Remove value from geneic dictionary

Imports System
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports System.ComponentModel

Public Class MainClass

   Shared Sub Main()
        Dim pair_dictionary As New PairDictionary(Of Integer, String, String)
        pair_dictionary.Add(10"A""A")
        pair_dictionary.Add(32"B""B")
        pair_dictionary.Add(17"C""C")

        pair_dictionary.Remove(32)

        ' Print the values for index 32.
        Dim value1 As String = ""
        Dim value2 As String = ""

        Try
            pair_dictionary.GetItem(32, value1, value2)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try

        Console.WriteLine("Value:" & value1 & ", " & value2)
   End Sub 

End Class



Public Class PairDictionary(Of KeyType, DataType1, DataType2)
    Private Structure DataPair
        Public Data1 As DataType1
        Public Data2 As DataType2
        Public Sub New(ByVal data_value1 As DataType1, ByVal data_value2 As DataType2)
            Data1 = data_value1
            Data2 = data_value2
        End Sub
    End Structure

    Private m_Dictionary As New Dictionary(Of KeyType, DataPair)

    Public ReadOnly Property Count() As Integer
        Get
            Return m_Dictionary.Count
        End Get
    End Property

    Public Sub Add(ByVal key As KeyType, ByVal data_value1 As DataType1, ByVal data_value2 As DataType2)
        m_Dictionary.Add(key, New DataPair(data_value1, data_value2))
    End Sub

    Public Sub Clear()
        m_Dictionary.Clear()
    End Sub

    Public Function ContainsKey(ByVal key As KeyTypeAs Boolean
        Return m_Dictionary.ContainsKey(key)
    End Function

    ' Return a data pair.
    Public Sub GetItem(ByVal key As KeyType, ByRef data_value1 As DataType1, ByRef data_value2 As DataType2)
        Dim data_pair As DataPair = m_Dictionary.Item(key)
        data_value1 = data_pair.Data1
        data_value2 = data_pair.Data2
    End Sub

    ' Set a data pair.
    Public Sub SetItem(ByVal key As KeyType, ByVal data_value1 As DataType1, ByVal data_value2 As DataType2)
        m_Dictionary.Item(key= _
            New DataPair(data_value1, data_value2)
    End Sub

    ' Return a collection containing the keys.
    Public ReadOnly Property Keys() As System.Collections.ICollection
        Get
            Return m_Dictionary.Keys()
        End Get
    End Property

    ' Remove a particular entry.
    Public Sub Remove(ByVal key As KeyType)
        m_Dictionary.Remove(key)
    End Sub
End Class

           
       
Related examples in the same category
1. Generic Dictionary: save and get dataGeneric Dictionary: save and get data
w___ww.j__a___v__a_2___s__._c__o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.