I have this code in VB.Net:
Dim c As Control
For Each c In Me.Controls
If TypeOf (c) is PictureBox Then
CType(c, PictureBox).Image = My.Resources.available
End If
Next
What is appropriate code in C#?
I have this code in VB.Net:
Dim c As Control
For Each c In Me.Controls
If TypeOf (c) is PictureBox Then
CType(c, PictureBox).Image = My.Resources.available
End If
Next
What is appropriate code in C#?
It is
((PictureBox)c).Image = ...
See https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/casting-and-type-conversions
You cast c
to PictureBox
Note that you can also do
if (c is PictureBox picbox)
{
picbox.Image = ...
}
This way you test that c is a PictureBox and (if so) immediately cast and store in that picbox
variable.