|
-
Dec 27th, 2003, 02:20 AM
#1
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()?
-
Dec 27th, 2003, 04:27 AM
#2
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:
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:
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]
-
Dec 27th, 2003, 01:25 PM
#3
PowerPoster
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.
-
Dec 27th, 2003, 05:55 PM
#4
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?
-
Dec 27th, 2003, 07:09 PM
#5
PowerPoster
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.
-
Dec 28th, 2003, 08:44 PM
#6
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, ***?
-
Dec 28th, 2003, 09:00 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|