Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > BOOK: Beginning Object-Oriented Programming with C#
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2015, 04:06 PM
Registered User
 
Join Date: Feb 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Understanding c# Object orientated program syntax

Hi every one, the book suggested that I should come here if I struggle so here I am!
Firstly I am already a coder at VB and Oracle SQL.
I understand and use Object orientated programming but I never formally picked it up, I just learned as I went.
The idea is to pick up C# but at the same time formalise my knowledge of OOP theory; to learn what I am actually doing instead of just knowing why I should.
I know im head over heels and backward (know and LOVE linq, but unsure of real OOP theory?) but its just the way my knowledge has developed.
So, hope some one can help!
under chapter 2, understanding objects, the author states that a statement should be written as 'clsPerson myFriend' then 'myFriend = new clsPerson();'.
so step by step with the authors code.
Firstly the author created a pointer called 'myFriend' which will point to an instance of the class clsPerson.
Now, what confuses is that in all programming languages I have used thus far, you follow the syntax 'varName var Type', this is what im used to.
e.g.
Dim myString as string
myString varchar2(255)
etc etc etc.
Its probably my inexperience with C#, but why is it swapped in this case? why is the varType first, then the varName second? Are we saying 'create a generic pointer, which will point to a clsPerson type? Therefore would 'string myString' -in theory- be valid as its a pointer?
I am struggling to wrap my head around this requirement.
Websites suggest writing the line combined as 'clsPerson myFriend = new clsPerson' but tht is no clearer even though I know it does the same thing.
by my understanding, when I create a 'myString varchar(255)' I am saying 'reserve a block of ram, the size and type of a char char, 256 long. when ever I refer to 'myString' I want you to refer to that varchar memory'.
by that same logic, in the above line I am saying 'a type of clsPerson, called myFriend, reserve memory for a clsPerson' and its that which breaks me down .
I hope I make sense.
P.s. The cookie cutter analogy, whilst good is maybe confusing me a little as its saying, to me, make a copy of the cookie cutter, then copy it again, then use the copy to punch out a space of ram and call it my friend. why make a copy of a copy?

Update:
Okay thinking about it a lot more, im starting to get a handle on it a little more now.
Ive gone about it the wrong way round. When you use the 'new' keyword and declare a class, it creates the memory space, but throws back a memory location. without some where to store the memory location it will fail. So we give it a place to store the memory location, myFriend. therefore we have to create that pointer first, which we do via 'clsPerson myFriend'.
The end result is that calling 'myFriend' calls the memory location created by the 'new' keyword earlier.
Still don't understand why the varType comes before the varName however or is this combination just the C# syntax for a pointer?

Last edited by TheOnlyPaulV; July 19th, 2015 at 04:17 PM.. Reason: A little more understanding
 
Old July 27th, 2015, 07:50 PM
Friend of Wrox
 
Join Date: Sep 2008
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Understanding C# Syntax

C# is not Visual Basic and its syntax is very different. The language is modeled after C, not any dialect of Basic. Defining a variable in C# is of the form:

Data_Type Variable_Name;

You keep complaining that it's different that VB. True, it is, but why are you complaining about it? If you want to code in VB, code in VB. If you want to code in C#, learn its syntax and quit complaining that it's different. Complaining is a complete waste of time.

As to the Cookie Cutter example, it is used to drive home the idea that a class is a model, or blueprint, for something. A set of blueprints is not a house, just like a class is not an object. To create an object, you use the set of plans dictated by the specifics detailed in the class code, starting with the constructor. The process of moving from a class specification to an object of that class is called object instantiation. The properties of the class determine the final "shape" the object has.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in understanding EnsureValidSortExp syntax dazy BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 January 25th, 2008 04:49 PM
Object reference Syntax help lidanny General .NET 5 September 3rd, 2006 07:17 AM
Object literal syntax shortt Javascript 4 May 28th, 2005 07:44 PM
Problem understanding Object creation cdplayer Classic ASP Basics 4 March 18th, 2004 07:04 PM
Syntax for OleDb Command Object Parameters aadz5 ASP.NET 1.0 and 1.1 Basics 4 November 20th, 2003 03:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.