So I have a class that spans over two partial classes in code, here's
an example (do not read much into this, the code is of no practical
use, this is just a simple example of where my confusion occurs).
// Inside SharedClassExam ple1.cs
public partial class SharedClassExam ple
{
public List<stringBook sOnShelf { get; set; }
public List<stringBook sOnDesk { get; set; }
// constructor
public SharedClassExam ple()
{
BooksOnShelf = new List<string>();
BooksOnDesk = new List<string>();
}
public void SortBooksOnShel f()
{
BooksOnShelf.So rt();
}
// why isn't this possible?
partial void RemoveBooksFrom ShelfAndDesk(st ring bookTitle)
{
BooksOnShef.Rem ove(bookTitle);
}
}
// inside SharedClassExam ple2.cs
public partial class SharedClassExam ple
{
public void SortBooksOnDesk ()
{
BooksOnDesk.Sor t();
}
// why isn't this possible?
partial void RemoveBooksFrom ShelfAndDesk(st ring bookTitle)
{
BooksOnDesk.Rem ove(bookTitle);
}
}
The above example generates a compile time error, after some research
on-line it appears partial methods do not work as I original
understood. Instead a "partial method" is simply defined in one file
(In context, "file" means one of the two files in which this class
lives, in two parts) and the implementation is provided in the other
file.
Some my question is this: If the implementation of the partial method
can not span across files, then what is the point? For example, in C#
2.0 with partial classes I could make a call SortBooksOnDesk from
inside SharedClassExam ple1.cs so why do I need this new mechanism of
seperating the implementation from the declaration?
an example (do not read much into this, the code is of no practical
use, this is just a simple example of where my confusion occurs).
// Inside SharedClassExam ple1.cs
public partial class SharedClassExam ple
{
public List<stringBook sOnShelf { get; set; }
public List<stringBook sOnDesk { get; set; }
// constructor
public SharedClassExam ple()
{
BooksOnShelf = new List<string>();
BooksOnDesk = new List<string>();
}
public void SortBooksOnShel f()
{
BooksOnShelf.So rt();
}
// why isn't this possible?
partial void RemoveBooksFrom ShelfAndDesk(st ring bookTitle)
{
BooksOnShef.Rem ove(bookTitle);
}
}
// inside SharedClassExam ple2.cs
public partial class SharedClassExam ple
{
public void SortBooksOnDesk ()
{
BooksOnDesk.Sor t();
}
// why isn't this possible?
partial void RemoveBooksFrom ShelfAndDesk(st ring bookTitle)
{
BooksOnDesk.Rem ove(bookTitle);
}
}
The above example generates a compile time error, after some research
on-line it appears partial methods do not work as I original
understood. Instead a "partial method" is simply defined in one file
(In context, "file" means one of the two files in which this class
lives, in two parts) and the implementation is provided in the other
file.
Some my question is this: If the implementation of the partial method
can not span across files, then what is the point? For example, in C#
2.0 with partial classes I could make a call SortBooksOnDesk from
inside SharedClassExam ple1.cs so why do I need this new mechanism of
seperating the implementation from the declaration?
Comment