Skip to content

Commit a1c2040

Browse files
committed
oops
1 parent db0d498 commit a1c2040

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

docs/csharp/programming-guide/delegates/delegates-with-named-vs-anonymous-methods.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.assetid: 98fa8c61-66b6-4146-986c-3236c4045733
1111

1212
A [delegate](../../language-reference/builtin-types/reference-types.md) can be associated with a named method. When you instantiate a delegate by using a named method, the method is passed as a parameter, for example:
1313

14-
[!code-csharp[csProgGuideDelegates#1](~/./snippets/Delegates.cs#1)]
14+
[!code-csharp[csProgGuideDelegates#1](./snippets/Delegates.cs#1)]
1515

1616
This is called using a named method. Delegates constructed with a named method can encapsulate either a [static](../../language-reference/keywords/static.md) method or an instance method. Named methods are the only way to instantiate a delegate in earlier versions of C#. However, in a situation where creating a new method is unwanted overhead, C# enables you to instantiate a delegate and immediately specify a code block that the delegate will process when it is called. The block can contain either a [lambda expression](../../language-reference/operators/lambda-expressions.md) or an [anonymous method](../../language-reference/operators/delegate-operator.md).
1717

@@ -31,11 +31,11 @@ var write = Console.Write; // ERROR: Multiple overloads, can't choose
3131

3232
The following is a simple example of declaring and using a delegate. Notice that both the delegate, `MultiplyCallback`, and the associated method, `MultiplyNumbers`, have the same signature
3333

34-
[!code-csharp[csProgGuideDelegates#2](~/./snippets/Delegates.cs#2)]
34+
[!code-csharp[csProgGuideDelegates#2](./snippets/Delegates.cs#2)]
3535

3636
In the following example, one delegate is mapped to both static and instance methods and returns specific information from each.
3737

38-
[!code-csharp[csProgGuideDelegates#3](~/./snippets/Delegates.cs#3)]
38+
[!code-csharp[csProgGuideDelegates#3](./snippets/Delegates.cs#3)]
3939

4040
## See also
4141

docs/csharp/programming-guide/delegates/how-to-combine-delegates-multicast-delegates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This example demonstrates how to create multicast delegates. A useful property o
1616

1717
## Example
1818

19-
[!code-csharp[csProgGuideDelegates#11](~/./snippets/Delegates.cs#11)]
19+
[!code-csharp[csProgGuideDelegates#11](./snippets/Delegates.cs#11)]
2020

2121
## See also
2222

docs/csharp/programming-guide/delegates/how-to-declare-instantiate-and-use-a-delegate.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ You can declare delegates using any of the following methods:
1313

1414
- Declare a delegate type and declare a method with a matching signature:
1515

16-
[!code-csharp[csProgGuideDelegates#13](~/./snippets/Delegates.cs#13)]
16+
[!code-csharp[csProgGuideDelegates#13](./snippets/Delegates.cs#13)]
1717

18-
[!code-csharp[csProgGuideDelegates#14](~/./snippets/Delegates.cs#14)]
18+
[!code-csharp[csProgGuideDelegates#14](./snippets/Delegates.cs#14)]
1919

2020
- Assign a method group to a delegate type:
2121

22-
[!code-csharp[csProgGuideDelegates#32](~/./snippets/Delegates.cs#32)]
22+
[!code-csharp[csProgGuideDelegates#32](./snippets/Delegates.cs#32)]
2323

2424
- Declare an anonymous method:
2525

26-
[!code-csharp[csProgGuideDelegates#15](~/./snippets/Delegates.cs#15)]
26+
[!code-csharp[csProgGuideDelegates#15](./snippets/Delegates.cs#15)]
2727

2828
- Use a lambda expression:
2929

30-
[!code-csharp[csProgGuideDelegates#31](~/./snippets/Delegates.cs#31)]
30+
[!code-csharp[csProgGuideDelegates#31](./snippets/Delegates.cs#31)]
3131

3232
For more information, see [Lambda Expressions](../../language-reference/operators/lambda-expressions.md).
3333

@@ -37,27 +37,27 @@ You can declare delegates using any of the following methods:
3737

3838
## Example
3939

40-
[!code-csharp[csProgGuideDelegates#12](~/./snippets/Delegates.cs#12)]
40+
[!code-csharp[csProgGuideDelegates#12](./snippets/Delegates.cs#12)]
4141

4242
## Robust Programming
4343

4444
- Declaring a delegate.
4545

4646
The following statement declares a new delegate type.
4747

48-
[!code-csharp[csProgGuideDelegates#16](~/./snippets/Delegates.cs#16)]
48+
[!code-csharp[csProgGuideDelegates#16](./snippets/Delegates.cs#16)]
4949

5050
Each delegate type describes the number and types of the arguments, and the type of the return value of methods that it can encapsulate. Whenever a new set of argument types or return value type is needed, a new delegate type must be declared.
5151

5252
- Instantiating a delegate.
5353

5454
After a delegate type has been declared, a delegate object must be created and associated with a particular method. In the previous example, you do this by passing the `PrintTitle` method to the `ProcessPaperbackBooks` method as in the following example:
5555

56-
[!code-csharp[csProgGuideDelegates#17](~/./snippets/Delegates.cs#17)]
56+
[!code-csharp[csProgGuideDelegates#17](./snippets/Delegates.cs#17)]
5757

5858
This creates a new delegate object associated with the [static](../../language-reference/keywords/static.md) method `Test.PrintTitle`. Similarly, the non-static method `AddBookToTotal` on the object `totaller` is passed as in the following example:
5959

60-
[!code-csharp[csProgGuideDelegates#18](~/./snippets/Delegates.cs#18)]
60+
[!code-csharp[csProgGuideDelegates#18](./snippets/Delegates.cs#18)]
6161

6262
In both cases a new delegate object is passed to the `ProcessPaperbackBooks` method.
6363

@@ -67,7 +67,7 @@ You can declare delegates using any of the following methods:
6767

6868
After a delegate object is created, the delegate object is typically passed to other code that will call the delegate. A delegate object is called by using the name of the delegate object, followed by the parenthesized arguments to be passed to the delegate. Following is an example of a delegate call:
6969

70-
[!code-csharp[csProgGuideDelegates#19](~/./snippets/Delegates.cs#19)]
70+
[!code-csharp[csProgGuideDelegates#19](./snippets/Delegates.cs#19)]
7171

7272
A delegate can be either called synchronously, as in this example, or asynchronously by using `BeginInvoke` and `EndInvoke` methods.
7373

docs/csharp/programming-guide/delegates/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A [delegate](../../language-reference/builtin-types/reference-types.md) is a typ
1313

1414
Delegates are used to pass methods as arguments to other methods. Event handlers are nothing more than methods that are invoked through delegates. You create a custom method, and a class such as a windows control can call your method when a certain event occurs. The following example shows a delegate declaration:
1515

16-
[!code-csharp[csProgGuideDelegates#20](~/./snippets/Delegates.cs#20)]
16+
[!code-csharp[csProgGuideDelegates#20](./snippets/Delegates.cs#20)]
1717

1818
Any method from any accessible class or struct that matches the delegate type can be assigned to the delegate. The method can be either static or an instance method. This flexibility means you can programmatically change method calls, or plug new code into existing classes.
1919

docs/csharp/programming-guide/delegates/using-delegates.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ ms.assetid: 99a2fc27-a32e-4a34-921c-e65497520eec
1010

1111
A [delegate](../../language-reference/builtin-types/reference-types.md) is a type that safely encapsulates a method, similar to a function pointer in C and C++. Unlike C function pointers, delegates are object-oriented, type safe, and secure. The type of a delegate is defined by the name of the delegate. The following example declares a delegate named `Callback` that can encapsulate a method that takes a [string](../../language-reference/builtin-types/reference-types.md) as an argument and returns [void](../../language-reference/builtin-types/void.md):
1212

13-
[!code-csharp[csProgGuideDelegates#21](~/./snippets/Delegates.cs#21)]
13+
[!code-csharp[csProgGuideDelegates#21](./snippets/Delegates.cs#21)]
1414

1515
A delegate object is normally constructed by providing the name of the method the delegate will wrap, or with a [lambda expression](../../language-reference/operators/lambda-expressions.md). Once a delegate is instantiated in this manner it can be invoked. Invoking a delegate calls the method attached to the delegate instance. The parameters passed to the delegate by the caller are passed to the method, and the return value, if any, from the method is returned to the caller by the delegate. For example:
1616

17-
[!code-csharp[csProgGuideDelegates#22](~/./snippets/Delegates.cs#22)]
17+
[!code-csharp[csProgGuideDelegates#22](./snippets/Delegates.cs#22)]
1818

19-
[!code-csharp[csProgGuideDelegates#23](~/./snippets/Delegates.cs#23)]
19+
[!code-csharp[csProgGuideDelegates#23](./snippets/Delegates.cs#23)]
2020

2121
Delegate types are derived from the <xref:System.Delegate> class in .NET. Delegate types are [sealed](../../language-reference/keywords/sealed.md)—they cannot be derived from— and it is not possible to derive custom classes from <xref:System.Delegate>. Because the instantiated delegate is an object, it can be passed as an argument, or assigned to a property. This allows a method to accept a delegate as a parameter, and call the delegate at some later time. This is known as an asynchronous callback, and is a common method of notifying a caller when a long process has completed. When a delegate is used in this fashion, the code using the delegate does not need any knowledge of the implementation of the method being used. The functionality is similar to the encapsulation interfaces provide.
2222

2323
Another common use of callbacks is defining a custom comparison method and passing that delegate to a sort method. It allows the caller's code to become part of the sort algorithm. The following example method uses the `Del` type as a parameter:
2424

25-
[!code-csharp[csProgGuideDelegates#24](~/./snippets/Delegates.cs#24)]
25+
[!code-csharp[csProgGuideDelegates#24](./snippets/Delegates.cs#24)]
2626

2727
You can then pass the delegate created above to that method:
2828

29-
[!code-csharp[csProgGuideDelegates#25](~/./snippets/Delegates.cs#25)]
29+
[!code-csharp[csProgGuideDelegates#25](./snippets/Delegates.cs#25)]
3030

3131
and receive the following output to the console:
3232

@@ -38,29 +38,29 @@ Using the delegate as an abstraction, `MethodWithCallback` does not need to call
3838

3939
When a delegate is constructed to wrap an instance method, the delegate references both the instance and the method. A delegate has no knowledge of the instance type aside from the method it wraps, so a delegate can refer to any type of object as long as there is a method on that object that matches the delegate signature. When a delegate is constructed to wrap a static method, it only references the method. Consider the following declarations:
4040

41-
[!code-csharp[csProgGuideDelegates#26](~/./snippets/Delegates.cs#26)]
41+
[!code-csharp[csProgGuideDelegates#26](./snippets/Delegates.cs#26)]
4242

4343
Along with the static `DelegateMethod` shown previously, we now have three methods that can be wrapped by a `Del` instance.
4444

4545
A delegate can call more than one method when invoked. This is referred to as multicasting. To add an extra method to the delegate's list of methods—the invocation list—simply requires adding two delegates using the addition or addition assignment operators ('+' or '+='). For example:
4646

47-
[!code-csharp[csProgGuideDelegates#27](~/./snippets/Delegates.cs#27)]
47+
[!code-csharp[csProgGuideDelegates#27](./snippets/Delegates.cs#27)]
4848

4949
At this point `allMethodsDelegate` contains three methods in its invocation list—`Method1`, `Method2`, and `DelegateMethod`. The original three delegates, `d1`, `d2`, and `d3`, remain unchanged. When `allMethodsDelegate` is invoked, all three methods are called in order. If the delegate uses reference parameters, the reference is passed sequentially to each of the three methods in turn, and any changes by one method are visible to the next method. When any of the methods throws an exception that is not caught within the method, that exception is passed to the caller of the delegate and no subsequent methods in the invocation list are called. If the delegate has a return value and/or out parameters, it returns the return value and parameters of the last method invoked. To remove a method from the invocation list, use the [subtraction or subtraction assignment operators](../../language-reference/operators/subtraction-operator.md) (`-` or `-=`). For example:
5050

51-
[!code-csharp[csProgGuideDelegates#28](~/./snippets/Delegates.cs#28)]
51+
[!code-csharp[csProgGuideDelegates#28](./snippets/Delegates.cs#28)]
5252

5353
Because delegate types are derived from `System.Delegate`, the methods and properties defined by that class can be called on the delegate. For example, to find the number of methods in a delegate's invocation list, you may write:
5454

55-
[!code-csharp[csProgGuideDelegates#29](~/./snippets/Delegates.cs#29)]
55+
[!code-csharp[csProgGuideDelegates#29](./snippets/Delegates.cs#29)]
5656

5757
Delegates with more than one method in their invocation list derive from <xref:System.MulticastDelegate>, which is a subclass of `System.Delegate`. The above code works in either case because both classes support `GetInvocationList`.
5858

5959
Multicast delegates are used extensively in event handling. Event source objects send event notifications to recipient objects that have registered to receive that event. To register for an event, the recipient creates a method designed to handle the event, then creates a delegate for that method and passes the delegate to the event source. The source calls the delegate when the event occurs. The delegate then calls the event handling method on the recipient, delivering the event data. The delegate type for a given event is defined by the event source. For more, see [Events](../events/index.md).
6060

6161
Comparing delegates of two different types assigned at compile-time will result in a compilation error. If the delegate instances are statically of the type `System.Delegate`, then the comparison is allowed, but will return false at run time. For example:
6262

63-
[!code-csharp[csProgGuideDelegates#30](~/./snippets/Delegates.cs#30)]
63+
[!code-csharp[csProgGuideDelegates#30](./snippets/Delegates.cs#30)]
6464

6565
## See also
6666

0 commit comments

Comments
 (0)