I'm helping a colleague develop a "catch all" type error handler for some controls his application. What he wants to do is pass the object that has the error, and the type of that object, such a TextBox or ComboBox, and then call the DirectCast method within his handler to properly address the Text attribute within it. In general, the me...
Public Enum Fruit
Red_Apple = 1
Oranges
Ripe_Banana
End Enum
Private Sub InitCombosRegular()
Dim d1 As New Dictionary(Of Int16, String)
For Each e In [Enum].GetValues(GetType(Fruit))
d1.Add(CShort(e), Replace(e.ToString, "_", " "))
Next
ComboBox1.DataSource = d1.ToList
ComboBox1.DisplayMember = "V...
How come this is not a valid DirectCast:
Public Sub FB(OF T0 As IGH_Goo, T1 As IGH_Goo) _
(ByVal A As DataTree(Of T0), _
ByVal B As DataTree(Of T1))
Dim val_A As T1 = DirectCast(A.FirstItem, T1)
End Sub
whereas this is:
Public Sub FB(OF T0 As IGH_Goo, T1 As IGH_Goo) _
(ByVal A As DataTree...
Sometimes I have to implement an interface or inherit a virtual (MustInherit) that the base method expects an object, whilst I know that the value I will be passing will always be an Integer for example.
What should be the best performance from the examples below:
Public Sub DoSomething(ByVal obj As Object)
'option 1:
Dim x As ...
i have 1 a.master page and 1 b.aspx with its b.aspx.vb page. I have the following property in the a.master.vb
Public Property Page_Title() As String
Get
Return title_div.InnerHtml
End Get
Set(ByVal value As String)
title_div.InnerHtml = value
End Set
End Property
in the b.aspx.vb page i have
DirectCast...
Whenever Resharper encounters code like this:
(treeListNode.Tag as GridLine).AdvertiserSeparation = 5;
it presents you with a possible fix (since treeListNode.Tag as GridLine might be null). It says: 'Replace with Direct Cast', which turns the code into the following:
((GridLine) treeListNode.Tag).AdvertiserSeparation = 5;
This is...
This has probably been asked before, but if it has, I can't find it.
Does C# have an equivalent to VB.Net's DirectCast?
I am aware that it has () casts and the 'as' keyword, but those line up to CType and TryCast.
To be clear, these keywords do the following;
CType/() casts: If it is already the correct type, cast it, otherwise look f...
Ever since I moved from VB6 to VB.NET somewhere in 2005, I've been using CType to do casting from one data type to another. I do this because it is simply faster to type, used to exist in VB6 and I do not know why I have to be using DirectCast if there is apparently no difference between them.
I use TryCast once in a while because I und...
I am an experienced C/C++/C# programmer who has just gotten into VB.NET. I generally use CType (and CInt, CBool, CStr) for casts because it is less characters and was the first way of casting which I was exposed to, but I am aware of DirectCast and TryCast as well.
Simply, are there any differences (effect of cast, performance, etc.)...