Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

resize

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Deniel Rose' - 18 Nov 2006 05:44 GMT
How can I resize a list ? thanks
Dave Sexton - 18 Nov 2006 05:52 GMT
Hi Deniel,

If it's some sort of list Control to which you are referring then:

- for WinForms set any of the Bounds, ClientSize, Size, Width or Height
properties

- for WebControl set the Width or Height properties or add custom attributes
and styles.

Signature

Dave Sexton

> How can I resize a list ? thanks
Deniel Rose' - 18 Nov 2006 06:00 GMT
class A {
  public int a;
}
private void func()
{
  List<A> aref=new List<A>();
  //dosometing
  aref.resize(10000); <------ This is what i want to do
}

But there is no resize() implemeted.
Thanks for any help

> Hi Deniel,
>
[quoted text clipped - 10 lines]
>
> > How can I resize a list ? thanks
Dave Sexton - 18 Nov 2006 06:19 GMT
Hi Deniel,

List<T> will expand on its own when you add items to the list.  You can set
the Capacity, which affects how automatic resizing occurs within the List.

"List<T> Capacity Property"
http://msdn2.microsoft.com/en-us/library/y52x03h2.aspx

Signature

Dave Sexton

> class A {
>   public int a;
[quoted text clipped - 24 lines]
>>
>> > How can I resize a list ? thanks
Deniel Rose' - 18 Nov 2006 06:34 GMT
Thanks Dave for your answer,
I still wonder how i can sort the list based on the comparison of "a"
values

I mean
private bool comp(A aref, A bref)
{
   return aref.a<bref.a;
}
if i put this function in a icomparable, implementation may become
complex,
built-in sort of List can't do this, can it ? How can I make a sort()
then ?

> Hi Deniel,
>
[quoted text clipped - 35 lines]
> >>
> >> > How can I resize a list ? thanks
Mark R. Dawson - 18 Nov 2006 06:59 GMT
Hi Deniel,
 here is an example of how you can sort the contents of your list using an
anonymous delegate, which makes it very simple to sort the items in the list:

class Person
{
           private string name;

           public Person(string name)
           {
               this.name = name;
           }

           public string Name
           {
               get
               {
                   return this.name;
               }
           }
       }
       static void Main(string[] args)
       {
           List<Person> people = new List<Person>();

           Person mark = new Person("mark");
           Person bob = new Person("bob");
           Person frank = new Person("frank");

           people.Add(mark);
           people.Add(bob);
           people.Add(frank);

           people.Sort(delegate(Person p1, Person p2)
                                 {
                                       return p1.Name.CompareTo(p2.Name);
                                 }
           );

           for (int i = 0; i < people.Count; ++i)
           {
               Console.Out.WriteLine(people[i].Name);
           }

           Console.ReadLine();
       }

HTH
Mark.
Signature

http://www.markdawson.org

> Thanks Dave for your answer,
> I still wonder how i can sort the list based on the comparison of "a"
[quoted text clipped - 49 lines]
> > >>
> > >> > How can I resize a list ? thanks
Dave Sexton - 18 Nov 2006 07:03 GMT
Hi Deniel,

Try the following code:

List<int> list = new List<int>();
list.Add(10);
list.Add(3);
list.Add(16);

list.Sort(
   delegate(int i1, int i2)     // anonymous method
   {
       return i1.CompareTo(i2);
   });

Signature

Dave Sexton

> Thanks Dave for your answer,
> I still wonder how i can sort the list based on the comparison of "a"
[quoted text clipped - 49 lines]
>> >>
>> >> > How can I resize a list ? thanks
Deniel Rose' - 18 Nov 2006 06:46 GMT
Thanks Dave for your help

> Hi Deniel,
>
[quoted text clipped - 35 lines]
> >>
> >> > How can I resize a list ? thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.