Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 23-Dec-11 1:39am
v2
Comments
Nikil S 23-Dec-11 7:34am    
Your question is not very clear.
bbirajdar 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. :)

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

C#
List<yourclass>  Listname  = new List<yourclass>();
 
Share this answer
 
v2
C#
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();
        }
    }
}
 
Share this answer
 
C#
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:
C#
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...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900