bungpeng Posted January 21, 2003 Posted January 21, 2003 Can I define a "Abstract" class in VB.NET? It means I do not need to create a object to refers to this class; I can direct use the methods/functions of the class without declared any object. I use it before in "Java" Quote
*Gurus* divil Posted January 21, 2003 *Gurus* Posted January 21, 2003 You can declare static members of a class using the Shared keyword in VB.NET: Public Class Class1 Public Shared Sub Boo() End Sub End Class You would then be able to call Class1.Boo() without an instance of the class. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bungpeng Posted January 21, 2003 Author Posted January 21, 2003 Is it? I though this is only a 'static' variable type in normal class? Quote
*Gurus* divil Posted January 21, 2003 *Gurus* Posted January 21, 2003 Static variables in vb.net remain in existence and retain their latest values after termination of the procedure in which they are declared. They are not the same as shared members of classes. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bungpeng Posted January 23, 2003 Author Posted January 23, 2003 I not quite undertanding, then what different between 'static' variables and 'shared' variables? How do I declare 'static' variable? with 'Static' keyword? Quote
*Experts* Volte Posted January 23, 2003 *Experts* Posted January 23, 2003 Static var As IntegerWhen the variables go out of scope, they retain their values (though can't be accessed from outside of the procedure they're declared in). The term Static comes from the fact that the variable keeps a static location in memory, thus preserving the data. Quote
bungpeng Posted January 23, 2003 Author Posted January 23, 2003 You mean "Shared" and "Static" are the same, the only different is that 'Static' can't be access from outside the procedure? right? Actually what is the purpose for Microsoft to do that? Why don't use the same? either 'Shared' or 'Static'? Quote
*Experts* Volte Posted January 23, 2003 *Experts* Posted January 23, 2003 No, Shared means that a sub inside a class can be accessed from anywhere, without declaring an instance of the class. In VB6, a public method in a module did what a shared method in a class does in VB.NET; although modules still exist in .NET, you should use Shared methods in classes. Quote
bungpeng Posted January 23, 2003 Author Posted January 23, 2003 In this case: I create a class 'Car' with 2 functions 'A' and 'B'. 'A' declare as "Shared", 'B' is normal public function. If I want to access these functions (A and B), then do I need to create object for class 'Car'? This is what I confuse now.... Sorry because disturb you again... Quote
*Gurus* divil Posted January 23, 2003 *Gurus* Posted January 23, 2003 All this information is covered in great details in the help file, within the Visual Basic .NET language reference. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted January 23, 2003 *Experts* Posted January 23, 2003 I believe he said the Language Reference. Check out the keyword "Shared", "Static" etc. and read as much as you can - there is a GREAT deal of info around the class and member modifiers (such as public, private, shared, etc.). It's well worth the effort to spend 8 hours or so writing small sample classes and seeing what each keyword does and doesn't do. A book on VB.NET would cover this as well with good samples. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
bungpeng Posted January 24, 2003 Author Posted January 24, 2003 I try to read more detail, i hope this is what i want... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.