diff --git a/docs/csharp/misc/cs0193.md b/docs/csharp/misc/cs0193.md index 40d5db085dcbf..dcc7673c4ba1d 100644 --- a/docs/csharp/misc/cs0193.md +++ b/docs/csharp/misc/cs0193.md @@ -1,7 +1,7 @@ --- description: "Compiler Error CS0193" title: "Compiler Error CS0193" -ms.date: 07/20/2015 +ms.date: 05/27/2025 f1_keywords: - "CS0193" helpviewer_keywords: @@ -10,9 +10,9 @@ ms.assetid: 7b60fd99-9eee-4d61-ad75-585a16e22e96 --- # Compiler Error CS0193 -The \* or -> operator must be applied to a pointer +The \* or -> operator must be applied to a data pointer -The \* or -> operator was used with a nonpointer type. For more information, see [Pointer types](../language-reference/unsafe-code.md#pointer-types). +The \* or -> operator was used with a nonpointer type or with a function pointer. Function pointers cannot be dereferenced in C#. For more information, see [Pointer types](../language-reference/unsafe-code.md#pointer-types) and [Function pointers](../language-reference/unsafe-code.md#function-pointers). The following sample generates CS0193: @@ -45,3 +45,19 @@ public class MyClass } } ``` + +The following example shows that function pointers cannot be dereferenced in C#, unlike in C/C++: + +```csharp +unsafe class FunctionPointerExample +{ + public static void Log() { /* ... */ } + + public static unsafe void Example() + { + delegate* fp = &Log; // pointer to managed function Log() + fp(); // OK; call Log() via function pointer + (*fp)(); // Error; CS0193, function pointers cannot be dereferenced + } +} +```