Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
Dim s As New System.Collections.Generic.Stack(Of Int32)
s.Push(5) 'no boxing
s.Push(6)
's.Push("invalid") 'will not compile :-)
Dim tot As Int32 = s.Pop() + s.Pop() 'no cast
System.Collections.Generic.Stack<int> s;
s = new Stack<int>();
s.Push(5); //no boxing
s.Push(6);
//s.Push("invalid"); //will not compile :-)
int tot = s.Pop() + s.Pop(); //no cast
Public Structure MyPoint(Of T)
Dim x As T
Dim y As T
End Structure
public struct MyPoint<T> {
T x;
T y;
}
Dim mp As New MyPoint(Of Single)
mp.x = 12.3
mp.y = 5
MyPoint<float> mp = new MyPoint<float>();
mp.x = 12.3;
mp.y = 5.2;
Public NotInheritable Class MyMath
Private Sub New()
End Sub
Public Shared Function Min(Of T As IComparable)(ByVal a As T, ByVal b As T) As T
If a.CompareTo(b) < 0 Then 'no casting + intellisense help
Return a
End If
Return b
End Function
End Class
public static class MyMath {
//Min with constraints
public static T Min<T>(T a, T b) where T : IComparable {
if (a.CompareTo(b) < 0) {//no casting + intellisense help
return a;
return b;
Dim m As Int32 = MyMath.Min(6, 8)
int m = MyMath.Min(6, 8);