# HierarchicalKey.TryFormat(Span&lt;char&gt;, int, ReadOnlySpan&lt;char&gt;, IFormatProvider?)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/methods/)

[Source](https://github.com/dotnet/orleans/blob/6a0e937f544c35ffcf11b37e4c2b7de5a1580a03/src/Orleans.Durable/Messaging/HierarchicalKey.cs#L224-L230)

```csharp
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
```

Tries to format the value of the current instance into the provided span of characters.

### Parameters

- `destination` (`Span<char>`): The span in which to write this instance's value formatted as a span of characters.
- `charsWritten` (`int`): When this method returns, contains the number of characters that were written in `destination`.
- `format` (`ReadOnlySpan<char>`): A span containing the characters that represent a standard or custom format string that defines the acceptable format for `destination`.
- `provider` (`IFormatProvider?`): An optional object that supplies culture-specific formatting information for `destination`.

### Returns

`true` if the formatting was successful; otherwise, `false`.
