Click here to Skip to main content
12,068,108 members (39,911 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hi,

   i want to create a list object. in that list object i want add two values i.e. name, description. the name will be same but the description will be multiple. so have to create a string array for description. and i want the count of the description entered.

Regards,\
Basha
Posted 23-Dec-11 2:30am
Edited 23-Dec-11 2:39am
v2
Comments
Nikil S 23-Dec-11 7:34am
   
Your question is not very clear.
B Birajdar 23-Dec-11 7:37am
   
The count of the count can be counted by counting the number of count items in the count array. (PI)
RaviRanjankr 23-Dec-11 16:07pm
   
Not clear for me. will you give more information about your question. :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Best would be to create a class of the objects you want in that list
and then define your List as:

List<yourclass>  Listname  = new List<yourclass>();
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

using System;
using System.Collections.Generic;
using System.Linq;
 
namespace PrintPrice
{
    class Price
    {
        static void Main()
        {
            List<int> list = new List<int>();
            list.Add(1);
            list.Add(2);
 
            // Count with the Count property.
            int c = list.Count;
            Console.WriteLine(c);
 
            // Count with the extension method. This is different!
            c = list.Count(); // BE CAREFUL!
            Console.WriteLine(c);
 
            Console.ReadKey();
        }
    }
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

public class MyObject
{
    public string Name { get; set; }
    public string Description { get; set; }
    public MyObject():this("", "")
    {
    }
    public MyObject(string name, string desc)
    {
        this.Name = name;
        this.Description = desc;
    }
}
 
public class MyObjectCollection() : List<MyObject>
{
}
Usage:
MyObjectCollection objects = new MyO bjectCollection();
objects.Add(new MyObject("John", "Outlaw Programmer"));
// or
objects.Add(new MyObject() { Name="John", Description="Outlawprogrammer" } );
// or
MyObject obj = new MyObject("John", "Outlaw Programmer");
objects.Add(obj);
// or
MyObject obj = new MyObject(){Name="John", Description="Outlaw Programmer"};
objects.Add(obj);
It ain't rocket surgery...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 23 Dec 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100