?
Solved

Why can't use private specifier in C#

Posted on 2009-04-22
8
Medium Priority
?
242 Views
Last Modified: 2013-12-17
It compiles, but if you uncomment "private", it fails to compile.  WHY?
Using VS 2005.

using System;
 
namespace myNameSpace
{
    public class MyClass1
    {
          public int age;
    };
 
    public class MyClass2
    {
        public void foo()
        {
            /* private*/ MyClass1 myClass1;
        }
    };
};

Open in new window

0
Comment
Question by:brotherbill999
  • 4
  • 4
8 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 2000 total points
ID: 24207290
because local variables can't be private they are just local (local to the method)
private is used for class variables/members.
0
 

Author Comment

by:brotherbill999
ID: 24207362
Local variables may not have public, protected or private specifiers.
They are local to the procedure or function and are visible only within that procedure or function.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24207377
another way to say what i did, yes -- did you find that on msdn or something?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Closing Comment

by:brotherbill999
ID: 31573417
Thanx for instant response.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24207389
um no, i already told you that. just in different words.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24207394
crap, sorry -- thanks
0
 

Author Comment

by:brotherbill999
ID: 24207405
No, just figured it out and avoided being embarrassed by such a simple question.
0
 

Author Comment

by:brotherbill999
ID: 24207432
Sorry for not awarding you points.  We crossed in the mail, and you did deserve the points.  Maybe admin could award you the points on request...
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

840 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