Asked by:
best naming practise for class objects

Question
-
User-1982615125 posted
hi..
i have a class FloorType (which describes properties for a Type of Floor (such as grass, street, etc)
in the same class as where the FloorType class is, i want to create an instance of this class. but i cant use the same name because its already used.
what is the best naming practise in this scenario?
Nameing the Class FloorTypeClass and the object FloorType, seems a bit uncomfy.
Friday, February 2, 2018 6:53 PM
All replies
-
User1904516115 posted
You can use camel-casing.
FloorType floorType =new FloorType();
You can also use "this" keyword to refer object of current class or directly you can use class member in same class.
Friday, February 2, 2018 8:09 PM -
User-1982615125 posted
that is the worst practise ever.
that and 1000 other improvements in the hugely underrated vb.net makes me use it. plus, it makes my usefull screen solution even insaner.
i mean.. i have a class
Class
'in this class i have a class and an instance of it
dim test as test 'this word is already used
class test
end class
end class
Friday, February 2, 2018 9:40 PM -
User2053451246 posted
that is the worst practise ever.
that and 1000 other improvements in the hugely underrated vb.net makes me use it. plus, it makes my usefull screen solution even insaner.
i mean.. i have a class
Class
'in this class i have a class and an instance of it
dim test as test 'this word is already used
class test
end class
end class
Friday, February 2, 2018 9:48 PM -
User475983607 posted
fazioliamboina
that is the worst practise ever.
that and 1000 other improvements in the hugely underrated vb.net makes me use it. plus, it makes my usefull screen solution even insaner.
i mean.. i have a class
Class
'in this class i have a class and an instance of it
dim test as test 'this word is already used
class test
end class
end class
It is certainly possible to have a Floor class and create an instance of Floor pointed to by a variable name floor.
Public Class Floor Public Overrides Function ToString() As String Return "Hey, from Floor!" End Function End Class
Implementation
Sub Main() Dim floor As New Floor() Console.WriteLine(floor.ToString()) End Sub
Result
Hey, from Floor!
If you are trying to create an Instance of Floor within floor that is also possible.
Public Class Floor Dim floor As Floor Public Function FlootMemberToString() As String floor = New Floor Return "FlootMemberToString -> " & Me.floor.ToString() End Function Public Overrides Function ToString() As String Return "Hey, from Floor!" End Function End Class
An older local member naming convention is m_floor but this has been simplified to _floor over time. You'll see the underscore in C# too.
Public Class Floor Dim _floor As Floor Public Function FlootMemberToString() As String _floor = New Floor Return "FlootMemberToString -> " & _floor.ToString() End Function Public Overrides Function ToString() As String Return "Hey, from Floor!" End Function End Class
VB naming converntions have been around a long time and are well documented. Start by reading the VB.NET programming guide.
Coding conventions
Older naming converntions that still common.
https://msdn.microsoft.com/en-us/library/aa263493(v=vs.60).aspx
Friday, February 2, 2018 10:29 PM -
User541108374 posted
Hi,
VB is not case-sensitive so "this" is the same as "This" as far as it's concerned.Actually the C# alternative for this in VB.NET is Me.
Kris.
Monday, February 19, 2018 9:49 AM