The C# equivalent is an indexer, which requires enumerating the values. In
essence, what you desire is the ability to do the following (VB.NET code):
MyClass.Exposure("channel1") = 1
MyClass.Exposure("channel2") = 2
In C#, the closest is something like:
MyClass.Exposure[1] = 1;
MyClass.Exposure[2] = 2;
This, however, means you have to trap the indexed values somewhere, like:
Hashtable lookup = new Hashtable();
lookup.Add("channel1", 1);
lookup.Add("channel2", 2);
You can then run against the object like so:
MyClass.Exposure[Convert.ToInt32(lookup["channel1"])] = 1;
MyClass.Exposure[Convert.ToInt32(lookup["channel2"])] ] = 2;
This is an architectural difference between C# and VB.NET. But, there is a
good reason. In VB.NET, this is perfectly legal:
Public Property Exposure(ByRef UnrelatedCrap1 As String, _
ByRef UnrelatedCrap2 As String, _
ByRef ObjectInitializationSettings As
Hashtable, _
ByRef DisposeMeNow As Boolean, _
ByRef DoAWebServiceLookup As Boolean, _
) As Single
If (UnrelatedCrap1 = "MakeTheObjectDance") Then
MakeTheObjectDance()
End If
End Property
And, believe it or not, there are people who have done this in apps (of
course, it meant I had to explain the bloodstains in my trunk ;->).
---
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Razzerroo" wrote:
Hello all
I'm currently converting me and our code from VB.NET to C# for the
company I work for.
I have an VB.NET interface that has an excerpt like this:
Public Interface ISensorCameraSettings
..
..
..
Property Exposure(ByVal ChannelName As String) As Single
Property Gain(ByVal ChannelName As String) As Integer
Property BitRange(ByVal ChannelName As String) As Integer
..
..
..
End Interface
I can't figure the syntax to convert this to C#. . .
I've tried many iterations, I'm sure I just havent found the correct
thread on google or msdn?
something like:
public interface ICameraSettings
{
/// <summary>
/// Set the exposure for this sensor.
/// </summary>
void set_Exposure(string DataBufferName,float value);
float get_Exposure(string DataBuffername);
}
???
Please help.
Sincerely,
Kevin Christopher