Making a collection inside a class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sunfire

    #1

    Making a collection inside a class

    How do you make a collection inside a class and then access it? I am trying
    to make a class that is a news item and dont know where to really start. Any
    ideas?



  • Kerem Gümrükcü

    #2
    Re: Making a collection inside a class

    Hi Stranger,

    first at all: Real Names please!

    Depending on your need you can declare the Collection
    as a variable, with appropriate scope or the way i recommend
    and i think is always the right you should make the collection
    a class property, also with apropriate scope, where scope stands
    for access modifiers like private, protected, internal, public or
    whatever your project needs. keep in mind that you should code
    with pragmatic in mind: Safe Initialization and complete cleanup.

    Thats what i recommend,...ot hers may not or they will follow
    another aproach,...


    Cheers,...

    Kerem

    --
    ---------
    New Open Source Tools from me:
    Calculate MD5 or SHA1 Hash for Files!
    KHash Tools:

    ---------


    Beste Grüsse / Best regards / Votre bien devoue

    Kerem Gümrükcü
    kerem.g@arcor.d e

    Best Quote: "Ain't nobody a badass with a double dose
    of rock salt...", Kill Bill Vol.2

    Latest Open-Source Projects: http://entwicklung.junetz.de
    Sign my guestbook: http://entwicklung.junetz.de/guestbook/

    -----------------------
    "This reply is provided as is, without warranty express or implied."


    Comment

    • Andy B

      #3
      Re: Making a collection inside a class

      Is there a way you can give me a code example? Nothing too huge but
      something enough to give me an idea of what I'm doing...


      "Kerem Gümrükcü" <kareem114@hotm ail.comwrote in message
      news:e3gD1LCKIH A.4688@TK2MSFTN GP06.phx.gbl...
      Hi Stranger,
      >
      first at all: Real Names please!
      >
      Depending on your need you can declare the Collection
      as a variable, with appropriate scope or the way i recommend
      and i think is always the right you should make the collection
      a class property, also with apropriate scope, where scope stands
      for access modifiers like private, protected, internal, public or
      whatever your project needs. keep in mind that you should code
      with pragmatic in mind: Safe Initialization and complete cleanup.
      >
      Thats what i recommend,...ot hers may not or they will follow
      another aproach,...
      >
      >
      Cheers,...
      >
      Kerem
      >
      --
      ---------
      New Open Source Tools from me:
      Calculate MD5 or SHA1 Hash for Files!
      KHash Tools:

      ---------
      >
      >
      Beste Grüsse / Best regards / Votre bien devoue
      >
      Kerem Gümrükcü
      kerem.g@arcor.d e
      >
      Best Quote: "Ain't nobody a badass with a double dose
      of rock salt...", Kill Bill Vol.2
      >
      Latest Open-Source Projects: http://entwicklung.junetz.de
      Sign my guestbook: http://entwicklung.junetz.de/guestbook/
      >
      -----------------------
      "This reply is provided as is, without warranty express or implied."
      >
      >

      Comment

      • DeveloperX

        #4
        Re: Making a collection inside a class

        On 16 Nov, 08:48, "Andy B" <a_bo...@sbcglo bal.netwrote:
        Is there a way you can give me a code example? Nothing too huge but
        something enough to give me an idea of what I'm doing...
        >
        "Kerem Gümrükcü" <kareem...@hotm ail.comwrote in message
        >
        news:e3gD1LCKIH A.4688@TK2MSFTN GP06.phx.gbl...
        >
        >
        >
        Hi Stranger,
        >
        first at all: Real Names please!
        >
        Depending on your need you can declare the Collection
        as a variable, with appropriate scope or the way i recommend
        and i think is always the right you should make the collection
        a class property, also with apropriate scope, where scope stands
        for access modifiers like private, protected, internal, public or
        whatever your project needs. keep in mind that you should code
        with pragmatic in mind: Safe Initialization and complete cleanup.
        >
        Thats what i recommend,...ot hers may not or they will follow
        another aproach,...
        >
        Cheers,...
        >
        Kerem
        >
        --
        ---------
        New Open Source Tools from me:
        Calculate MD5 or SHA1 Hash for Files!
        KHash Tools:
        http://entwicklung.junetz.de/project...ools/khashtool...
        ---------
        >
        Beste Grüsse / Best regards / Votre bien devoue
        >
        Kerem Gümrükcü
        kere...@arcor.d e
        >
        Best Quote: "Ain't nobody a badass with a double dose
        of rock salt...", Kill Bill Vol.2
        >
        Latest Open-Source Projects:http://entwicklung.junetz.de
        Sign my guestbook:http://entwicklung.junetz.de/guestbook/
        >
        -----------------------
        "This reply is provided as is, without warranty express or implied."- Hide quoted text -
        >
        - Show quoted text -
        Here's a dotnet 2 class that shows the basics using a generic
        dictionary. You can use similar techniques with a List amongst others
        depending on your requirements. Collections is quite a broad topic
        though.

        using System;
        using System.Collecti ons.Generic;
        using System.Text;
        using System.Runtime. CompilerService s;

        namespace ClassLibrary1
        {
        public class Indexy
        {
        private Dictionary<stri ng, string_bits = new
        Dictionary<stri ng, string>();

        [IndexerName("Va lue")]
        public string this[String key]
        {
        set
        {
        if (_bits.Contains Key(key))
        {
        _bits[key] = value;
        }
        else
        {
        _bits.Add(key, value);
        }
        }
        get
        {
        if (_bits.Contains Key(key))
        {
        return _bits[key];
        }
        else
        {
        return string.Empty;
        }
        }
        }
        public int Count()
        {
        return _bits.Count;
        }
        public Dictionary<stri ng, stringMyDiction ary
        {
        get
        {
        return _bits;
        }
        }
        }
        }

        Comment

        • Andrew Thompson

          #5
          Re: Making a collection inside a class

          On Nov 17, 12:06 am, DeveloperX <nntp...@operam ail.comwrote:
          ....
          ...(watch forline wrap).
          A small tool designed to help avoid line wrap.
          <http://www.physci.org/twc.jnlp>

          --
          Andrew T.
          PhySci.org

          Comment

          Working...