Use Operators with Custom Objects – Overloading
Public Shared Operator + (objA as myClass, objB as myClass ) as MyClass 'code End Operator
ObjC = ObjA + ObjB
Public Shared Operator + (objA as myClass, objB as myClass ) as MyClass 'code End Operator
ObjC = ObjA + ObjB
dim i as Nullable(Of Integer) If not i.HasValue then Console.WriteLine("i is a null value") End If i=100 If i.HasValue then Console.WriteLine("Nullable integer i = " & i.Value) End If
Example 1
Public Class GenericList(Of ItemType) 'Some Code End Class Example 2
Public Class GenericList(Of Item Type) Inherits CollectionBase Public Function Add(ByVal value as ItemType) as Integer Return List.Add(value) End Function Public Sub Remove(ByVal value as ItemValue) List.Remove(value) End Sub Public ReadOnly Property Item(ByVal index as Integer) as ItemType Get Return CType(List.Item(index),ItemType) End Get End Property End Class
Program Code
Dim List as New GenericList(Of String) List.Add("blue") List.Add("red") List.Add(Guid.NewGuid()) ' Will be detected by the compiler
Example 3 - More than one type parameter in the class
Public Class GenerichashTable(Of ItemType, KeyType) Inherits DictionaryBase 'Code End Class
Example 4 - Define Constraints to Parameters
Public Class SerializableList(Of ItemType as ISerializable) Inherits CollectionBase 'Code End Class Public Class ControlCollection(Of ItemType as Control) Inherits CollectionBase 'Code End Class If you want your class to create an instance of the Item
Public Class GenericList(Of ItemType as New) Inherits CollectionBase 'Code End Class Example 5 - Define more than one constraint
Public Class GenericList(Of ItemType as {ISerializable, New}) Inherits CollectionBase 'Code End Class Generics also works with structures, interfaces, deletates and methods.
Double Click the My Project node in the Solution Explorer and select the Settings tab. Add the Name, Type, Scope and Value of your setting.
From your code, type:
dim aSetting as string
aSetting=My.Settings.YourSettingName
If you select User from the Scope drop-down list, you can modify that setting in runtime. The modify your setting and save it like this:
MySettings.YourSettingName = “NewValue”
MySettings.Save()
This will create a file under Documents and Settings\[UserName]\Local Settings\Application Data\[Application Name]\[Unique Directory] for the current user only with the selected value.
This will embed the image in your assembly. If you want to modify the image, replace the image inside the Resource Directory and recompile. There is no need to modify the code.
This approach is better than the ImageList because ImageList does not support typed resources. However, there are controls that do no support it and you have to fill the imagelist with the resource images in your code if you want to use it in this way.
Type My. and select:
Information about the current computer, network, mouse and keyboard, printer, screen and clock. Also sounds, files, registry and clipboard
Information about current application and context, assembly version, current folder, culture, command line arguments and log events
Information about current user
Default instances to any form in the app and to communicate between forms without needing to track from references in another class.
Provides a default proxy-class instance for every web service
Allows you to retrieve custom settings from your application XML config file
Allows you to retrieve resources-blocks of binary or text data that are compiled intro your application assembly
Add ”’ before a sub or function, complete the fields, compile and see the xml file in your bin folder. Use NDoc or any other similar program to consume that xml file and create the xml documentation
Right-click on any local variable and select Rename. This will rename all appropriate instances in your code of that variable.
Symbolic Rename works with any property, class or method.
Right click on a form, and select rename. You will see the same result.