Results 1 to 7 of 7

Thread: Quick couple of questions

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Quick couple of questions

    1. What do I need to reference or use to use exemptions? I am porting some VB.NET code and I cannot use exemptions and it says (perhaps you're missing a reference or using statement)

    2. Why isn't their a ListBox1.Items.Item in C#? I need to use it!

    3. ListBox1.Items.Count() doesn't work the same in C## as it does in VB.NET. It denotes a property when it expects a method. how do I make it work like VB's cout()?

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    listbox.items.count works the same , if you want to retrieve it's count in anything other than an integer ( eg: a messagebox ) you must add .ToString()
    VB Code:
    1. MessageBox.Show(listBox1.Items.Count.ToString());
    as for items.item , the same effect is found with items( number of item ) eg: items(0) in vb.net. this is the way C# uses.
    VB Code:
    1. MessageBox.Show(listBox1.Items[0].ToString());
    hope it clears things up a bit
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    The reason you use this syntax in C# is because C# uses Indexers and VB.Net doesn't. Your other problems come from VB not being so strict with type conversions, and C# is.

  4. #4

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Alright thanks, when I fire up my other computer later I'll see if this works (i'm sure it will).



    However, does anyone have an answer for #1?

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I have no idea what a "exemptions" is, but if you mean exception, then it depends on what type of exception you are trying to use.

    The basic exception object uses System.Exception.

    Others are in different namespaces....such as IO exceptions are in the System.IO namespace.

  6. #6

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    I got everything figured out (I spelled Exceptions wrong, lol!) except one thing.

    ListBox1.Items.Count() doesn't seem to work.

    In VB.NET, I am using it in a for loop so I can compare an integer to the number of items in a listbox. Comparing an integer to ListBox1.Items.Count() works fine in VB.NET.

    However, in C#, I do this:
    Code:
    for(int i = 0; i < ListBox1.Items.Count(); i++)
    and get this error when building:
    Code:
    'System.Windows.Forms.ListBox.ObjectCollection.Count' denotes a 'property' where a 'method' was expected
    Uh, ***?

  7. #7

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Nevermind, it doesn't like the () in C#


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width