Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# Method Question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
tanjiajun_34
Grandmaster Cheater
Reputation: 0

Joined: 16 Feb 2006
Posts: 786
Location: Singapore

PostPosted: Sat May 29, 2010 11:07 pm    Post subject: C# Method Question Reply with quote

I am learning C# in school. I have a question about method.

May I know whats the private for?

Code:
private bool IsPrime(int num)
        {

        }


But

Code:
bool IsPrime(int num)
        {

        }


Works too?...
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat May 29, 2010 11:36 pm    Post subject: Reply with quote

In a class everything is private by default. So yes, it is optional in a class but you should add it anyways (at least, I do).
Back to top
View user's profile Send private message
tanjiajun_34
Grandmaster Cheater
Reputation: 0

Joined: 16 Feb 2006
Posts: 786
Location: Singapore

PostPosted: Sun May 30, 2010 8:35 am    Post subject: Reply with quote

Oh. So, if I type in public, what will happen? What the different with private and public?
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sun May 30, 2010 11:17 am    Post subject: Reply with quote

Public allows it to be accessed by other methods. Private dos not.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sun May 30, 2010 12:24 pm    Post subject: Reply with quote

CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

Not completely correct. public allows the methods to be used from other classes, private only allows it to be used from methods in the same class.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun May 30, 2010 12:34 pm    Post subject: Reply with quote

tombana wrote:
CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

Not completely correct. public allows the methods to be used from other classes, private only allows it to be used from methods in the same class.


There are two other access modifiers as well. 'protected' allows inheriting classes to use the method, and 'internal' is essentially 'public' but only to classes in the same assembly.
Back to top
View user's profile Send private message
potaters
Grandmaster Cheater
Reputation: 72

Joined: 13 Apr 2009
Posts: 969

PostPosted: Wed Jun 02, 2010 2:14 pm    Post subject: Reply with quote

CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

I'm pretty sure that's Java.
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Wed Jun 02, 2010 7:04 pm    Post subject: Reply with quote

xen0r wrote:
CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

I'm pretty sure that's Java.


Nah, I think it's just about every programming language that has that feature Razz Though I am not 100% correct, as I was corrected in a post above.
Back to top
View user's profile Send private message
potaters
Grandmaster Cheater
Reputation: 72

Joined: 13 Apr 2009
Posts: 969

PostPosted: Wed Jun 02, 2010 7:07 pm    Post subject: Reply with quote

CometJack wrote:
xen0r wrote:
CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

I'm pretty sure that's Java.


Nah, I think it's just about every programming language that has that feature Razz Though I am not 100% correct, as I was corrected in a post above.

I thought it was different for C#, meh, I've only done a little C#.
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Wed Jun 02, 2010 7:28 pm    Post subject: Reply with quote

xen0r wrote:
CometJack wrote:
xen0r wrote:
CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

I'm pretty sure that's Java.


Nah, I think it's just about every programming language that has that feature Razz Though I am not 100% correct, as I was corrected in a post above.

I thought it was different for C#, meh, I've only done a little C#.


It's okay Razz I'm not a master at C# though I've done quite a bit of simple applications and few difficult ones.

You can check some of my released C# sources here -> http://forum.cheatcity.org/forum-52.html
Back to top
View user's profile Send private message
1929394839292057839194958
Grandmaster Cheater Supreme
Reputation: 130

Joined: 22 Dec 2006
Posts: 1509

PostPosted: Thu Jun 03, 2010 3:40 am    Post subject: Reply with quote

xen0r wrote:
CometJack wrote:
xen0r wrote:
CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

I'm pretty sure that's Java.


Nah, I think it's just about every programming language that has that feature Razz Though I am not 100% correct, as I was corrected in a post above.

I thought it was different for C#, meh, I've only done a little C#.
C# (according to a fair few experts) is a lot like a mixture of C++ and Java.
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sat Jun 05, 2010 4:24 pm    Post subject: Reply with quote

konr wrote:
xen0r wrote:
CometJack wrote:
xen0r wrote:
CometJack wrote:
Public allows it to be accessed by other methods. Private dos not.

I'm pretty sure that's Java.


Nah, I think it's just about every programming language that has that feature Razz Though I am not 100% correct, as I was corrected in a post above.

I thought it was different for C#, meh, I've only done a little C#.
C# (according to a fair few experts) is a lot like a mixture of C++ and Java.


Yep Smile

You get all the nice features of C++ with the easy-to-learn/use syntax of Java!

You get the best of both worlds so-to-say.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Jun 12, 2010 7:02 pm    Post subject: Reply with quote

'private' does not stop other methods inside the same object from accessing the function in C#. Anything within the same object, in this case a class, is part of the same scope, which has access to each other.

Quick example:
Code:

    public class TestClass
    {
        public TestClass()
        {
        }

        private int Method1()
        {
            return 12345;
        }

        public int Method2()
        {
            return Method1();
        }
    }


Code:
TestClass tClass = new TestClass();
int nValue = tClass.Method2();
MessageBox.Show(nValue.ToString());


Method2 has access to Method1 regardless of it being private since they are defined within the same object. However, you cannot access Method1 outside of this instance without using Method2 due to Method1 being private.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
tanjiajun_34
Grandmaster Cheater
Reputation: 0

Joined: 16 Feb 2006
Posts: 786
Location: Singapore

PostPosted: Sat Jun 12, 2010 10:10 pm    Post subject: Reply with quote

So, to sum up, private methods cannot be access outside the class? Public can?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Jun 13, 2010 1:26 am    Post subject: Reply with quote

tanjiajun_34 wrote:
So, to sum up, private methods cannot be access outside the class? Public can?


Yes.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites