hi all, i've tried to extend on the default class size, but couldn't do so. example
public class psize
inherits size
end class
why is it that there is no such thing as size when im sure that i could create a new size(x, y)
Printable View
hi all, i've tried to extend on the default class size, but couldn't do so. example
public class psize
inherits size
end class
why is it that there is no such thing as size when im sure that i could create a new size(x, y)
What are you TRYING to do?
well im trying to create a new class psize that could have a method which multiply itself.
so
Code:dim test = new psize(50, 50)
test.multiply()
'effectively i should get a size (100, 100)
This is a VB.NET question. I am moving this thread to VB.NET forum.
Size is a structure and you cannot inherit from a structure. You should also look at the documentation when you face such kind of issues. Tomorrow you may find a class that is not inheritable just by reading MSDN for that particular class. Take a look at MSDN documentation for the Size.
If you want to have an additional method for an existing class or structure, you can try using extension methods. Extension methods give you a capability of adding additional methods to an existing class. Something like this should work for you, add a module to your application and then write this codeCode:Imports System.Runtime.CompilerServices
Module SizeExtensions
<Extension()> _
Public Function Multiply(ByRef pointSize As Size)
Return pointSize.Height * pointSize.Width
End Function
End Module
hey thanks, but for my case its not just multiply and i have to explicitly name it as Psize and not Size, is there a way to extend a class and at the same time making it only accessible to this extension by a new name?
so basically all i want is to be able to do this
[code]
dim test = new Psize(5, 5)
test.dosomething()
dim test2 = new Size(5, 5)
test2.dosomething() ' should give me an error
As I mentioned earlier, Size is a struct and you cannot inherit a structure.
so is there a solution to be able to do something like this:
Code:dim test = new Psize(5, 5)
test.dosomething()
dim test2 = new Size(5, 5)
test2.dosomething() ' should give me an error