Prev | Current Page 355 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

cs Example2.cs
Figure 7.1 Code in partial types is able to ???see??? all of the members of the type,
regardless of which file each member is in.
186 CHAPTER 7 Concluding C# 2: the final features
// Example1.cs
using System;
partial class Example
: IEquatable
where TFirst : class
{
public bool Equals(string other))
{
return false;
}
}
// Example2.cs
using System;
partial class Example
: EventArgs, IDisposable
{
public void Dispose()
{
}
}
I stress that this listing is solely for the purpose of talking about what??™s legal in a declaration
??”the types involved were only picked for convenience and familiarity. We can
see that both declarations (B and D) contribute to the list of interfaces that must
be implemented. In this example, each file implements the interfaces it declares,
and that??™s a common scenario, but it would be legal to move the implementation of
IDisposable E to Example1.cs and the implementation of IEquatable C
to Example2.cs. Only B specified any type constraints, and only C specified a base
class. If B specified a base class, it would have to be EventArgs, and if D specified
any type constraints they??™d have to be exactly as in B. In particular, we couldn??™t specify
a type constraint for TSecond in D even though it??™s not mentioned in B. Both
types have to have the same access modifier, if any??”we couldn??™t make one declaration
internal and the other public, for example.


Pages:
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367