Hi!
Can we have Access specifiers(like private or protected) inside a partial Class?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Feb 13, 2013, 3:14 AM
with the help of parial class, it is possible to split the definationof class in to two or more files. at the compiled time Compiler generate combine all partial class with same name.
Private, protected or protected internal cannot be explicity declared with in name space where class are define as partial.
yes you can any Access Modifiers with in partial class.
Example
file 1
partial class AAA
{
private string ABC = "jignesh";
}
file 2
partial class AAA
{
public void b()
{
ABC = "tejas";
}
}
hope this will help you
Upamanyu Roy ChoudhuryPosted Feb 20, 2013, 1:59 PM
We can have modifiers private or protected inside a partial class.
The following keywords on a partial-type definition are optional, but if present on one partial-type definition, cannot conflict with the keywords specified on another partial definition for the same type:
public
private
protected
internal
abstract
sealed
base class
new modifier (nested parts)
generic constraints
A partial type i.e. a class or say sturct is used in large projects where several developers need to work on the same type.
The types must all be present during the time of compilation to form the final type.
The class example of partial class is the asp.net's code behind class and the designer class, this way code and the UI are separated using the partial keyword , when we complie those files combine and form the final class.
The following links will give you an idea about the concept in depth
http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx
http://forums.asp.net/t/1409168.aspx/1
http://makhaai.blogspot.in/2009/05/partial-types-in-c.html
http://www.codeproject.com/Articles/313352/4-real-time-use-of-Partial-classes-and-partial-met
http://www.dotnetperls.com/partial
If you find this post as useful then please mark it as an answer
Dnyandeo ShindePosted Feb 15, 2013, 7:23 AM
Posted Feb 13, 2013, 2:15 AM
http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx