Skip to content

Commit eb52a69

Browse files
CopilotyufeihBillWagner
authored
Update CS0193 error message documentation for function pointers (#46423)
* Initial plan for issue * Update CS0193 error message documentation for function pointers Co-authored-by: yufeih <[email protected]> * Refine CS0193 documentation with additional unsafe context and links Co-authored-by: yufeih <[email protected]> * Update ms.date to 05/27/2025 as requested Co-authored-by: BillWagner <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: yufeih <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: Bill Wagner <[email protected]>
1 parent 0193d36 commit eb52a69

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

docs/csharp/misc/cs0193.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Compiler Error CS0193"
33
title: "Compiler Error CS0193"
4-
ms.date: 07/20/2015
4+
ms.date: 05/27/2025
55
f1_keywords:
66
- "CS0193"
77
helpviewer_keywords:
@@ -10,9 +10,9 @@ ms.assetid: 7b60fd99-9eee-4d61-ad75-585a16e22e96
1010
---
1111
# Compiler Error CS0193
1212

13-
The \* or -> operator must be applied to a pointer
13+
The \* or -> operator must be applied to a data pointer
1414

15-
The \* or -> operator was used with a nonpointer type. For more information, see [Pointer types](../language-reference/unsafe-code.md#pointer-types).
15+
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).
1616

1717
The following sample generates CS0193:
1818

@@ -45,3 +45,19 @@ public class MyClass
4545
}
4646
}
4747
```
48+
49+
The following example shows that function pointers cannot be dereferenced in C#, unlike in C/C++:
50+
51+
```csharp
52+
unsafe class FunctionPointerExample
53+
{
54+
public static void Log() { /* ... */ }
55+
56+
public static unsafe void Example()
57+
{
58+
delegate*<void> fp = &Log; // pointer to managed function Log()
59+
fp(); // OK; call Log() via function pointer
60+
(*fp)(); // Error; CS0193, function pointers cannot be dereferenced
61+
}
62+
}
63+
```

0 commit comments

Comments
 (0)