C#C
C#10mo ago
33 replies
noname7777

Array as Public Property; Need to Set Value at Index

I come from C/Lua/VBA background, very new to C# or anything like it.
Using .NET 9 and Onvif.core with VScodium/Omnisharp on Windows.

Onvif.core has this class:
    public class GetCapabilitiesRequest
    {
        [MessageBodyMember(Namespace = "http://www.onvif.org/ver10/device/wsdl", Order = 0)]
        [XmlElement("Category")]
        public CapabilityCategory[] Category;

        public GetCapabilitiesRequest();
        public GetCapabilitiesRequest(CapabilityCategory[] Category);
    }

CapabilityCategory is an enum:
public enum CapabilityCategory
{
  All = 0,
  Analytics = 1,
  Device = 2,
  Events = 3,
  Imaging = 4,
  Media = 5,
  PTZ = 6
}

I am trying to set the value of Category[0] to CapabilityCategory.ALL
This:
GetCapabilitiesRequest caps = new() {
  Category[0] = CapabilityCategory.All
}

Gives me some errors:
Cannot initialize type 'GetCapabilitiesRequest' with a collection initializer because it does not implement 'System.Collections.IEnumerable' [proj_name]
The name 'Category' does not exist in the current context [proj_name]
Invalid initializer member declarator [proj_name]

My normal approach of shotgunning different syntax has yielded nothing useful.
Tutorials point/W3 Schools and Microsoft documentation have also proven unhelpful.
The library documentation is non-existent, and the ONVIF Application programmer's guide is far too general in this case.
If more information is required I will be happy to provide it.
Thanks,
Was this page helpful?