473,671 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class, Constructor and Property - II

RP
Refer to my original post at:

http://groups.google.com/group/micro...202ff938fed637

I want to know:

(1) Is it necessary to define SET property if the constructor is
already there?

(2) When the constructor has been instantiated, I want to insert the
values in a table. Where the code to insert records must reside, in
the class itself or in the Button_Click event of Windows Form.

(3) Where I can find information about C# naming convention which is
used as a standard by developers?

Nov 8 '07 #1
3 1307
RP wrote:
Refer to my original post at:

http://groups.google.com/group/micro...202ff938fed637

I want to know:

(1) Is it necessary to define SET property if the constructor is
already there?
No. Only if you want to change the property *after* the object has been
constructed
>
(2) When the constructor has been instantiated, I want to insert the
values in a table. Where the code to insert records must reside, in
the class itself or in the Button_Click event of Windows Form.
I would not implement it inside the class, as it ties the class to a
specific purpose. however, I can't tell if the button click is a good
place to do so.
>
(3) Where I can find information about C# naming convention which is
used as a standard by developers?
http://msdn2.microsoft.com/en-us/lib...ke(vs.71).aspx

Can be enforced using FxCop. If you are using VS 2005, open the project
properties and navigate to "Code Analysis". If not, you can download the
FxCop tool.

HTH,
Andy
--
You can email me by removing the NOSPAM parts below:
xm**********@gm xNOSPAM.net
Nov 8 '07 #2
RP
I am still not following why a constructor and a property [with
GET ... SET] is used simultaneously. I noticed it in many examples. I
am new to OOP. The class which I created [see my original post] uses
both a constructor and properties. After setting values in property, I
am puzzled where to use a constructor and for what?

On Nov 8, 11:30 am, Andy Mueller <m...@privacy.n etwrote:
No. Only if you want to change the property *after* the object has been
constructed
Nov 8 '07 #3
There is no requirement to have a property in a class, and there is no
correlation from a constructor to a property. A property is simply a way of
encapsulating the desire to change a value of a facet of the object.

Some things, such as binding, only work with properties and not members.

Properties can be used to mask certain pieces of code behind the scenes.
For example, if you have a property on an object of class TicTacToeCell,
called CellValue, you may desire in the property set method, to check the
board to see if it causes a "win". If you did this with members rather than
properties, it would be somewhat more difficult.

I hope this helps a little.

"RP" wrote:
I am still not following why a constructor and a property [with
GET ... SET] is used simultaneously. I noticed it in many examples. I
am new to OOP. The class which I created [see my original post] uses
both a constructor and properties. After setting values in property, I
am puzzled where to use a constructor and for what?

On Nov 8, 11:30 am, Andy Mueller <m...@privacy.n etwrote:
No. Only if you want to change the property *after* the object has been
constructed

Nov 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
59241
by: Pavils Jurjans | last post by:
Hallo, Is there some decent way how to get the object class name in a string format? Currently I use this: function getClassName(obj) { if (typeof obj != "object" || obj === null) return false; return /(\w+)\(/.exec(obj.constructor.toString());
3
11825
by: Kirk Marple | last post by:
Just want to see if this is 'by design' or a bug... I have a common List<T> defined in a base class, and the base class has a static property to expose this list. I wanted the derived class to add items to this list, but have the base class hold the data and expose the property. Problem is, however, that the derived class' static constructor doesn't get called when DerivedClass.MyList is accessed, so the list has no members. If
0
3209
by: Daniel Sélen Secches | last post by:
I found a good class to do a simple FTP. Very good.... I'm posting it with the message, i hope it helps someone ============================================================== Imports System.Net
1
2249
by: John | last post by:
Hi, Maybe someone can help me with the following: "The first task by any derived class constructor is to call it’s direct or indirect base class constructor implicitly or explicitly", reads the statement. To test this, I added messageboxes in all constructors indicating which constructor is called. There are four constructors which could be called: 1. Base class empty constructor 2. Base class 2-Par. constructor
4
1538
by: Tony Johansson | last post by:
Hello! I have a class definition called MyClass see below. I create an instance of this class MyClass I also want this instance to be able to modify the test instance that exist in this class. I can make the instance of this class MyClass to be able to access the instance test in two ways.
0
8400
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8672
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7441
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6234
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4412
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.