# PdfDictionary class

> A PDF dictionary with keys in insertion order. Keys are names without the leading slash. Most PDF dictionaries hold a handful of keys, so lookups are...

Namespace: [PdfNetStack.Objects](https://www.jadev-corp.com/api/pdfnetstack-objects/)  
Assembly: PdfNetStack.dll  
Package: `PdfNetStack`

A PDF dictionary with keys in insertion order. Keys are names without the leading slash.
Most PDF dictionaries hold a handful of keys, so lookups are linear until the dictionary
grows, then switch to a hash index.

```csharp
public sealed class PdfDictionary : PdfObject, IEnumerable<KeyValuePair<string, PdfObject>>, IEnumerable
```

**Inheritance**

[object](https://learn.microsoft.com/dotnet/api/system.object) ← 
[PdfObject](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfobject/) ← 
[PdfDictionary](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfdictionary/)

**Implements**

[IEnumerable&lt;KeyValuePair&lt;string, PdfObject\>\>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable\-1), 
[IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable)

## Constructors

### <a id="PdfNetStack_Objects_PdfDictionary__ctor"></a> PdfDictionary\(\)

Creates an empty dictionary.

```csharp
public PdfDictionary()
```

## Properties

### <a id="PdfNetStack_Objects_PdfDictionary_Count"></a> Count

Number of entries.

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

#### Property Value

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

### <a id="PdfNetStack_Objects_PdfDictionary_Keys"></a> Keys

The keys, in insertion order.

```csharp
public IReadOnlyList<string> Keys { get; }
```

#### Property Value

 [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>

### <a id="PdfNetStack_Objects_PdfDictionary_Item_System_String_"></a> this\[string\]

The value for <code class="paramref">key</code>, or null when absent. The value may be a reference;
resolve it through the document. Setting null removes the entry.

```csharp
public PdfObject? this[string key] { get; set; }
```

#### Property Value

 [PdfObject](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfobject/)?

## Methods

### <a id="PdfNetStack_Objects_PdfDictionary_ContainsKey_System_String_"></a> ContainsKey\(string\)

True when the key is present.

```csharp
public bool ContainsKey(string key)
```

#### Parameters

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

#### Returns

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

### <a id="PdfNetStack_Objects_PdfDictionary_GetEnumerator"></a> GetEnumerator\(\)

Returns an enumerator that iterates through the collection.

```csharp
public IEnumerator<KeyValuePair<string, PdfObject>> GetEnumerator()
```

#### Returns

 [IEnumerator](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerator\-1)<[KeyValuePair](https://learn.microsoft.com/dotnet/api/system.collections.generic.keyvaluepair\-2)<[string](https://learn.microsoft.com/dotnet/api/system.string), [PdfObject](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfobject/)\>\>

An enumerator that can be used to iterate through the collection.

### <a id="PdfNetStack_Objects_PdfDictionary_GetName_System_String_"></a> GetName\(string\)

The value of <code class="paramref">key</code> when it is a direct name, without the slash.

```csharp
public string? GetName(string key)
```

#### Parameters

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

#### Returns

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

### <a id="PdfNetStack_Objects_PdfDictionary_Remove_System_String_"></a> Remove\(string\)

Removes an entry; returns false when it was absent.

```csharp
public bool Remove(string key)
```

#### Parameters

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

#### Returns

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

### <a id="PdfNetStack_Objects_PdfDictionary_Set_System_String_PdfNetStack_Objects_PdfObject_"></a> Set\(string, PdfObject\)

Adds or replaces an entry. Replacing keeps the key's position.

```csharp
public void Set(string key, PdfObject value)
```

#### Parameters

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

`value` [PdfObject](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfobject/)

### <a id="PdfNetStack_Objects_PdfDictionary_TryGetValue_System_String_PdfNetStack_Objects_PdfObject__"></a> TryGetValue\(string, out PdfObject\)

Gets the value for <code class="paramref">key</code> when present.

```csharp
public bool TryGetValue(string key, out PdfObject value)
```

#### Parameters

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

`value` [PdfObject](https://www.jadev-corp.com/api/pdfnetstack-objects/pdfobject/)

#### Returns

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

## Used in

- [Compress PDF files in C# and .NET](https://www.jadev-corp.com/guides/compress-pdf/)
- [Edit PDF pages in C# and .NET](https://www.jadev-corp.com/guides/edit-pages/)
- [Fill and create PDF forms in C# and .NET](https://www.jadev-corp.com/guides/forms/)
- [Low level PDF objects in C#](https://www.jadev-corp.com/guides/low-level-objects/)

Source: https://www.jadev-corp.com/pdfnetstack/api/pdfnetstack-objects/pdfdictionary/
