Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:43:03+00:00 2026-05-26T19:43:03+00:00

Is there a base class that I should inherit from that is just a

  • 0

Is there a base class that I should inherit from that is just a basic name/value pair?

For example, I have several classes that only have two properties (name and value). They all called something unique liked Field, Data, etc. and are all used for different things but the innards are all the same, two properties (name and value) and they have a related collection class that inherits from CollectionBase. Is there something I can do so they all share the same code or inherit from the same base class so it’s not so redundant? They are also located in different protection levels of the assembly as well so I don’t want to just use the same class for every scenario.

    Public Class Field

        Public Sub New()

        End Sub

        Private _name As String
        Public Property Name() As String
            Get
                Return _name
            End Get
            Set(ByVal value As String)
                _name = value
            End Set
        End Property

        Private _value As String
        Public Property Value() As String
            Get
                Return _value
            End Get
            Set(ByVal value As String)
                _value = value
            End Set
        End Property

    End Class


    Private NotInheritable Class FieldCollection
        Inherits CollectionBase

        Public Sub New()

        End Sub

        Public Sub Add(ByVal field As Field)
            List.Add(field)
        End Sub

        Public Sub Remove(ByVal index As Integer)
            If index > Count - 1 Or index < 0 Then
                Console.WriteLine("Can't remove this item")
            Else
                List.RemoveAt(index)
            End If
        End Sub

        Default Public ReadOnly Property Item(ByVal index As Integer) As Field
            Get
                Return CType(List.Item(index), Field)
            End Get
        End Property

    End Class

    Public Class Data

        Public Sub New()

        End Sub

        Private _name As String
        Public Property Name() As String
            Get
                Return _name
            End Get
            Set(ByVal value As String)
                _name = value
            End Set
        End Property

        Private _value As String
        Public Property Value() As String
            Get
                Return _value
            End Get
            Set(ByVal value As String)
                _value = value
            End Set
        End Property

    End Class


    Private NotInheritable Class DataCollection
        Inherits CollectionBase

        Public Sub New()

        End Sub

        Public Sub Add(ByVal data As Data)
            List.Add(data)
        End Sub

        Public Sub Remove(ByVal index As Integer)
            If index > Count - 1 Or index < 0 Then
                Console.WriteLine("Can't remove this item")
            Else
                List.RemoveAt(index)
            End If
        End Sub

        Default Public ReadOnly Property Item(ByVal index As Integer) As Data
            Get
                Return CType(List.Item(index), Data)
            End Get
        End Property

    End Class

etc…

UPDATE

Here’s a PasteBin of the code that I’m looking to streamline. Hopefully this helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:43:03+00:00Added an answer on May 26, 2026 at 7:43 pm

    See KeyValuePair<TKey, TValue>. This structure is used for example by .NET’s Dictionary<TKey, TValue> class to store generic values against a specific key and by the sounds of it should suit your requirements as long as inheritance is not an issue.

    If however you do want to use inheritance of any kind, then you can either use .NET4s Tuple<T1, T2> (Although this would result in .Item1, .Item2) or alternatively, if inheritance is really required / needed, use composition to wrap the KeyValuePair<TKey, TValue> into a custom object.

    Edit: Seeing your example this looks like a good use case for a Dictionary<string, string>. Is there a specific reason why you do not want to use a Dictionary or any of the other build in collection clases which’d be quite suitable for this? You can always “protect” certain classes by declaring them or their methods internal, private, protected etc to avoid them leaking too deep down, or too far up, your object model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a Base class and several Derived classes. Is there any
I have an interface for a base class, and every class that inherits from
I have a library base class ( Controller ) and three sub-classes that inherit
I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
In VB.NET there is a keyword 'shadows'. Let's say I have a base class
I have an abstract base class that many classes extend. I'd like all these
Ok, I should simply tell that I want to make a base Singleton class
Consider the following problem: You have a class 'A' that serves as a base
Are there any dictionary classes in the .NET base class library which allow duplicate
Is there anyway to discover the base class of a class in Python? For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.