Solved

public vs private classes

Posted on 2003-10-25
5
326 Views
Last Modified: 2010-04-16
I need a "for dummies" anwser of the difference between public and private classes.
0
Comment
Question by:chilled2003
5 Comments
 

Author Comment

by:chilled2003
ID: 9621167
ok figured this one out, what does the "static" mean in public static void Main() ?
0
 
LVL 1

Accepted Solution

by:
marcin1 earned 50 total points
ID: 9621188
There are two places where you can put your class definition:

A. Inside the namespace
B. Inside other class (nested classes)

A. This is the regular way to define classes:

namespace MyNamespace
{
      class MyClass {...}
}

In front of the class keyword you can put one of the access modifiers:

public   - the class is visible everywhere
internal - the visibility of the class is restricted to the current assembly

So if you have two projects, and you define a public class in one of them,
you can use this class in the second project. If you don't want this (you want
to hide your class), you use internal keyword.

B. If you define class A, and you want to define a helper class, you can
do it inside the body of class A:

namespace MyNamespace
{
      class A
      {
            ...
            public class Nested {...}
            ...
      }
}

In this case you can use one of the following access modifiers:
public, protected, internal, private.

They work the same way as put in front of the properties or fields.

Short explanation:
public - the nested class is visible outside class A
protected - the nested class is visible only inside class A and it
      is visible in classes which derive from A
private - the nested class is visible only inside class A and it
      is NOT visible in classes which derive from A
internal - the class is visible only in the current assembly
0
 

Expert Comment

by:soft_developer
ID: 9621334
in simple,
A public class can be instantiated by any object in the application
and
A Private Class can be created only by objects of its own type or by types that it nested off.

dzelters.
0
 

Author Comment

by:chilled2003
ID: 9621483
Thanks :)
0
 
LVL 1

Expert Comment

by:kellycoinguy
ID: 9623901

static on a function means that you don't need an object to invoke the function. It also implies that inside the function, there is no access to "this", although static members are available.

-Kelly
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now