# OpcStructField Members

> Reference: Represents a field of a structure defined using OpcStruct.

<dl class="api-definition">
<dt>Type</dt>
<dd><a href="./">OpcStructField</a></dd>
<dt>Namespace</dt>
<dd><a href="../namespaces/opc.uafx">Opc.UaFx</a></dd>
<dt>Assembly</dt>
<dd>Opc.UaFx.Advanced.dll</dd>
<dt>Package</dt>
<dd>Opc.UaFx.Advanced v2.59.0</dd>
</dl>

## Constructors

### OpcStructField

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [OpcStructField(string, OpcNodeId)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#opcstructfield-system-string-opc-uafx-opcnodeid) | Initializes a new instance of the [OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/) class using the unique `name` and `fieldTypeId` of the structure field to define. |
| [OpcStructField(string, OpcNodeId, string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#opcstructfield-system-string-opc-uafx-opcnodeid-system-string) | Initializes a new instance of the [OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/) class using the unique `name`, `fieldTypeId` and `description` of the structure field to define. |

#### OpcStructField(string, OpcNodeId)

Initializes a new instance of the [OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/) class using the unique `name` and `fieldTypeId` of the structure field to define.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField(string name, OpcNodeId fieldTypeId)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(name As String, fieldTypeId As OpcNodeId)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `name` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the structure field which unique identifies the field in the structure. |
| `fieldTypeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The identifier of the data type the field uses for its value. |

#### OpcStructField(string, OpcNodeId, string)

Initializes a new instance of the [OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/) class using the unique `name`, `fieldTypeId` and `description` of the structure field to define.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField(string name, OpcNodeId fieldTypeId, string description)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Sub New(name As String, fieldTypeId As OpcNodeId, description As String)
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `name` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the structure field which unique identifies the field in the structure. |
| `fieldTypeId` | [OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/) | The identifier of the data type the field uses for its value. |
| `description` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The description of the purpose of the structure field. |

## Properties

### ArrayRank

Gets the number of dimensions of the field if it is an array.

<div class="api-signature" data-lang="csharp">

```csharp
public int ArrayRank { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property ArrayRank As Integer
```

</div>

**Property value**

[Int32](https://learn.microsoft.com/dotnet/api/system.int32)

The number of dimensions set using [AsArray](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-system-int32-system-int64) or [AsArray](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-system-int32-system-string), or -1 if the field is not an array.

### Description

Gets description of the structure field which defines the purpose of the field.

<div class="api-signature" data-lang="csharp">

```csharp
public string Description { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Description As String
```

</div>

**Property value**

[String](https://learn.microsoft.com/dotnet/api/system.string)

The description of the purpose of the structure field represented.

### FieldTypeId

Gets the identifier of the data type of the value of the field.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcNodeId FieldTypeId { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property FieldTypeId As OpcNodeId
```

</div>

**Property value**

[OpcNodeId](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcnodeid/)

The identifier of the data type of the value.

### IsArray

Gets a value indicating whether the field is an array.

<div class="api-signature" data-lang="csharp">

```csharp
public bool IsArray { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property IsArray As Boolean
```

</div>

**Property value**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the field has been declared as an array using one of the [AsArray](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-noparams) methods; otherwise the value false.

### IsOptional

Gets a value indicating whether the field is optional.

<div class="api-signature" data-lang="csharp">

```csharp
public bool IsOptional { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property IsOptional As Boolean
```

</div>

**Property value**

[Boolean](https://learn.microsoft.com/dotnet/api/system.boolean)

The value true if the field has been declared as optional using one of the [AsOptional](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asoptional-noparams) methods; otherwise the value false.

### Length

Gets the length of the field if it is an array.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcMemberLength Length { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Length As OpcMemberLength
```

</div>

**Property value**

[OpcMemberLength](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcmemberlength/)

The length set using one of the [AsArray](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-noparams) methods, or a null reference (Nothing in Visual Basic) if the field is not an array.

### Name

Gets the name of the structure field which unique identifies the field in the structure.

<div class="api-signature" data-lang="csharp">

```csharp
public string Name { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Name As String
```

</div>

**Property value**

[String](https://learn.microsoft.com/dotnet/api/system.string)

The unique name of the structure field.

### Switch

Gets the switch which controls the existence of the field if it is optional.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcMemberSwitch Switch { get; }
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public ReadOnly Property Switch As OpcMemberSwitch
```

</div>

**Property value**

[OpcMemberSwitch](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcmemberswitch/)

The switch set using [AsOptional](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asoptional-opc-uafx-opcmemberswitch), or a null reference (Nothing in Visual Basic) if none has been set.

## Methods

### AsArray

<span class="api-meta">5 overloads</span>

| Overload | Description |
|---|---|
| [AsArray()](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-noparams) | Declares the field as a one-dimensional array with a variable length. |
| [AsArray(long)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-system-int64) | Declares the field as a one-dimensional array with the `length` specified. |
| [AsArray(string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-system-string) | Declares the field as a one-dimensional array whose length is the value of the field specified. |
| [AsArray(int, long)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-system-int32-system-int64) | Declares the field as an array with the `rank` and the `length` specified. |
| [AsArray(int, string)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asarray-system-int32-system-string) | Declares the field as an array with the `rank` specified whose length is the value of the field specified. |

#### AsArray()

Declares the field as a one-dimensional array with a variable length.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField AsArray()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AsArray() As OpcStructField
```

</div>

**Returns**

[OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/)

This field.

**Remarks**

A new value of the field starts as an empty array.

#### AsArray(long)

Declares the field as a one-dimensional array with the `length` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField AsArray(long length)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AsArray(length As Long) As OpcStructField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `length` | [Int64](https://learn.microsoft.com/dotnet/api/system.int64) | The number of elements of the array, or 0 for an array with a variable length. |

**Returns**

[OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/)

This field.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception) | The `length` is less than zero. |

**Remarks**

A new value of a field with the length 0 starts as an empty array.

#### AsArray(string)

Declares the field as a one-dimensional array whose length is the value of the field specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField AsArray(string lengthField)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AsArray(lengthField As String) As OpcStructField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `lengthField` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the field whose value is the length of the array; it is to precede this field. |

**Returns**

[OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/)

This field.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `lengthField` is equals [Empty](https://learn.microsoft.com/dotnet/api/system.string.empty). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `lengthField` is a null reference (Nothing in Visual Basic). |

#### AsArray(int, long)

Declares the field as an array with the `rank` and the `length` specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField AsArray(int rank, long length)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AsArray(rank As Integer, length As Long) As OpcStructField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `rank` | [Int32](https://learn.microsoft.com/dotnet/api/system.int32) | The number of dimensions of the array, from 1 to 32. |
| `length` | [Int64](https://learn.microsoft.com/dotnet/api/system.int64) | The number of elements of the array, or 0 for an array with a variable length. |

**Returns**

[OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/)

This field.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception) | The `rank` is less than 1 or greater than 32, or the `length` is less than zero. |

**Remarks**

A new value of a field with the length 0 starts as an empty array.

#### AsArray(int, string)

Declares the field as an array with the `rank` specified whose length is the value of the field specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField AsArray(int rank, string lengthField)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AsArray(
    rank As Integer,
    lengthField As String) As OpcStructField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `rank` | [Int32](https://learn.microsoft.com/dotnet/api/system.int32) | The number of dimensions of the array, from 1 to 32. |
| `lengthField` | [String](https://learn.microsoft.com/dotnet/api/system.string) | The name of the field whose value is the length of the array; it is to precede this field. |

**Returns**

[OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/)

This field.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) | The `lengthField` is equals [Empty](https://learn.microsoft.com/dotnet/api/system.string.empty). |
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `lengthField` is a null reference (Nothing in Visual Basic). |
| [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception) | The `rank` is less than 1 or greater than 32. |

### AsOptional

<span class="api-meta">2 overloads</span>

| Overload | Description |
|---|---|
| [AsOptional()](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asoptional-noparams) | Declares the field as optional. |
| [AsOptional(OpcMemberSwitch)](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/members#asoptional-opc-uafx-opcmemberswitch) | Declares the field as optional whose existence is controlled by the switch specified. |

#### AsOptional()

Declares the field as optional.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField AsOptional()
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AsOptional() As OpcStructField
```

</div>

**Returns**

[OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/)

This field.

#### AsOptional(OpcMemberSwitch)

Declares the field as optional whose existence is controlled by the switch specified.

<div class="api-signature" data-lang="csharp">

```csharp
public OpcStructField AsOptional(OpcMemberSwitch memberSwitch)
```

</div>

<div class="api-signature" data-lang="vbnet">

```vbnet
Public Function AsOptional(memberSwitch As OpcMemberSwitch) As OpcStructField
```

</div>

**Parameters**

| Name | Type | Description |
|---|---|---|
| `memberSwitch` | [OpcMemberSwitch](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcmemberswitch/) | The switch which controls the existence of the field. |

**Returns**

[OpcStructField](https://www.traeger.de/en/docs/development/opcua/api/v2.59/opc.uafx.opcstructfield/)

This field.

**Exceptions**

| Exception | Condition |
|---|---|
| [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) | The `memberSwitch` is a null reference (Nothing in Visual Basic). |
