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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 12, 2013, 10:14 PM EST
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
Posted Feb 12, 2013, 9:15 PM EST
http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx
Dnyandeo Shinde31 reputationPosted Feb 15, 2013, 2:23 AM EST
Upamanyu Roy Choudhury146 reputationPosted Feb 20, 2013, 8:59 AM EST
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