use of c# nested class and accessiblity

i am aware of nested class. how could i design my nested class in such way that out side of parent class of nested class no one will be able to access nested class like instance create etc because i want the child class will be private. i want to expose my child class property, method everything by parent class property or method. please guide me to write the code for such kind of nested class. thanks

public class Person
{
private string _firstName;
private string _lastName;
private DateTime _birthday;

//...

public class FirstNameComparer : IComparer<Person>
{
    public int Compare(Person x, Person y)
    {
        return x._firstName.CompareTo(y._lastName);
    }
}

}

Answers


Mark the internal class as private instead of public.

public class Person
{
    private string _firstName;
    private string _lastName;
    private DateTime _birthday;

    private FirstNameComparer firstNameComparer = new FirstNameComparer();

    public int CompareFirstNames(Person x, Person y)
    {
       return firstNameComparer.Compare(x, y);
    }

    //...

    private class FirstNameComparer : IComparer<Person>
    {
        public int Compare(Person x, Person y)
        {
            return x._firstName.CompareTo(y._lastName);
        }
    }
}

Need Your Help

Ideal example of a Use Case diagram

uml use-case

I am looking for an ideal example of a Use Case diagram which would explain most of the tricky places and be a good model for new Use Case diagrams.

Identifying a sklearn-model's classes

python scikit-learn svm

The documentation on SVMs implies, that an attribute called 'classes_' exists, which hopefully reveals how the model represents classes internally.