private C# with Example



private C# with Example

The private keyword marks properties, methods, fields and nested classes for use inside the class only: 
public class Foo() 
{ 
private string someProperty { get; set; } 
private class Baz 
{ 
public string Value { get; set; } 
} 
public void Do() 
{ 
var baz = new Baz { Value = 42 }; 
} 
} 
 

public class Bar() 
{ 
public Bar() 
{ 
var myInstance = new Foo(); 
// Compile Error - not accessible due to private modifier 
var someValue = foo.someProperty; 
// Compile Error - not accessible due to private modifier 
var baz = new Foo.Baz(); 
} 
} 

0 Comment's

Comment Form

Submit Comment