Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > BOOK: Beginning Object-Oriented Programming with C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Object-Oriented Programming with C#
This is the forum to discuss the Wrox book Beginning Object-Oriented Programming with C# by Jack Purdum; ISBN: 978-1-1183-3692-2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Object-Oriented Programming with C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 27th, 2013, 04:18 AM
Authorized User
Points: 90, Level: 1
Points: 90, Level: 1 Points: 90, Level: 1 Points: 90, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2012
Posts: 19
Thanks: 8
Thanked 0 Times in 0 Posts
Default Class private member and class static member difference ?

Hi .
I could not understand difference between private and static member in classes.
The code within class has direct access to objects in both of them.
So the difference is : when you use static member, you don't need to instantiate an object. is it right ?

Thank u.
  #2 (permalink)  
Old June 29th, 2013, 02:38 PM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default static versus private.

Suppose you have a class named clsPerson with a private member named Age. if you write code that creates 100 clsPerson objects, you will get 100 private members named Age.

Now suppose that class has a variable defined as:

static String days[]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};

Because you used the keyword static the compiler does two important things:

1) Immediately at program start, it creates the days[] array, even if you have not defined a clsPerson yet.
2) It will never create another days[] array regardless of how many other new clsPerson objects you define.

This means that every clsPerson object shares the same days[] array...it is never reassigned. Therefore, anytime you have data that likely won't change during program execution, making it a static can save code space by not duplicating the data. It should also be obvious that static data within methods retains its values between calls to the method.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
The Following User Says Thank You to DrPurdum For This Useful Post:
kafshdoozak (June 30th, 2013)
  #3 (permalink)  
Old June 30th, 2013, 02:05 AM
Authorized User
Points: 90, Level: 1
Points: 90, Level: 1 Points: 90, Level: 1 Points: 90, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2012
Posts: 19
Thanks: 8
Thanked 0 Times in 0 Posts
Default static and private

Hi.
Thank you so much .
Before your explanation i hadn't got the differences .
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch7 Const Member Functions of a Class proslambano BOOK: Ivor Horton's Beginning Visual C++ 2005 1 March 5th, 2007 04:01 PM
Arraylist::Sort() by class member jilly Visual C++ 2005 0 March 22nd, 2006 05:49 PM
How to Assign a Desc. to a Class Member BrianWren VB.NET 2002/2003 Basics 3 June 1st, 2005 02:07 PM
Invoking event from member variable class adxabuan Visual C++ 0 February 2nd, 2004 05:04 AM
Forum class (member) explination?? drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 0 June 15th, 2003 07:46 PM



All times are GMT -4. The time now is 02:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.