Select to view content in your preferred language

Turn layers on/off with C#

2677
2
03-04-2011 06:22 AM
DonFreeman
Emerging Contributor
I have some VB code which works fine to turn layers on and off. It looks something like this.
Dim layers As New List(Of Integer)()
If High_Checkbox.IsChecked Then
   layers.Add(8)
  End If

  'etc...
  Dim layer As ArcGISDynamicMapServiceLayer = TryCast(MyMap.Layers("SchoolSearch3"), ArcGISDynamicMapServiceLayer)
  layer.VisibleLayers = layers.ToArray()

I would like to convert it to C# but I get a syntax error on this line
ArcGISDynamicMapServiceLayer layer = MyMap.Layers("TitleVI") as ArcGISDynamicMapServiceLayer;
So how would this be done in C#?
Thanks
0 Kudos
2 Replies
DarinaTchountcheva
Frequent Contributor
Use square brackets:

ArcGISDynamicMapServiceLayer layer = MyMap.Layers["TitleVI"] as ArcGISDynamicMapServiceLayer;
0 Kudos
DonFreeman
Emerging Contributor
Use square brackets:

ArcGISDynamicMapServiceLayer layer = MyMap.Layers["TitleVI"] as ArcGISDynamicMapServiceLayer;


Thanks Darina. I thought I had tried that but I guess I hadn't.
0 Kudos