I have this problem with my code, I get an exception during compilation. Can anyone help me out?
if (Page.IsPostBack != false)
{
System.Drawing.KnownColor enClr;
System.Collections.Generic.List<System.Drawing.KnownColor> ColorList;
ColorList.AddRange(Enum.GetValues(enClr.GetType()));
}
I'm trying to follow this guide in VB.Net, but I only use C# so I'm trying to translate as I go, can anyone help?
Here's the original code:
If Not IsPostBack Then
Dim enClr As System.Drawing.KnownColor
Dim clrs As New _
System.Collections.Generic.List _
(Of System.Drawing.KnownColor)
clrs.AddRange(System.Enum.GetValues _
(enClr.GetType()))
DropDownList1.DataSource = clrs
DropDownList1.DataBind()
Best Solution
First of all it's confusing which direction you're trying to translate. The tags say C# to VB, but the text says VB to C#. I'm assuming the latter. With that in mind, this:
and this:
mean the exact opposite. Your C# should look like this:
You also need to pay closure attention to the word "New" in the vb code. A full adaption looks like this:
Finally, one more correction in your terminology: compile time errors are not exceptions. Excpetions are a run time construct.