473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Should I assign a Field to something? Pros/Cons please?

EARNEST
128 100+
Hello there.

Should I assign? Can you please explain why or why not, the reasons, please?

Warning:
Expand|Select|Wrap|Line Numbers
  1. is never assigned to, and will always have its default value null
Code:
Expand|Select|Wrap|Line Numbers
  1.     class f_Definition
  2.     {
  3.         string _definitionAcronym;
  4.         string _definitionName;
  5.         double[] _definitionValue = new double[4];
  6.         DefinitionValue _DefValue;
  7.  
  8.         //properties
  9.         public string DefinitionAcronym
  10.         {
  11.             set { _definitionAcronym = value; }
  12.             get { return _definitionAcronym;  }
  13.         }
  14.  
  15.         public string DefinitionName
  16.         {
  17.             get { return _definitionName; }
  18.         }
  19.  
  20.  
in first case, with set, does it assign it automatically? for that field, no warning generated. for the second property, there is a warning.

Thanks, and sorry if this question is silly
Dec 14 '10 #1

✓ answered by peochei

This happens when you declare a variable without assigning any value to it. It is not an error but compiler warns you that you might have forgot doing so.

You can leave the field _definitionName undeclared, however omitting setter in the property which wraps this variable you have disabled the possibility of assigning a value to this variable. You should consider whether this variable is needed or you can just delete it.

When designing classes that are just prototypes pieces of application you should consider using auto-implemented properties.

2 1597
peochei
12
This happens when you declare a variable without assigning any value to it. It is not an error but compiler warns you that you might have forgot doing so.

You can leave the field _definitionName undeclared, however omitting setter in the property which wraps this variable you have disabled the possibility of assigning a value to this variable. You should consider whether this variable is needed or you can just delete it.

When designing classes that are just prototypes pieces of application you should consider using auto-implemented properties.
Dec 14 '10 #2
EARNEST
128 100+
very helpful. thanks
Dec 14 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sniffle | last post by:
Thanks... Say you have a double opt in mailing list, of which the subcriber list is store in the db. Im still somewhat of a newb, so bear with me... are there any pros/cons as to keeping the...
3
by: Terry Parker | last post by:
I have a database that stores text (and other objects) which I would like to categorize under multiple categories. I started out creating a "SET" field with the different category names and I...
0
by: Steve | last post by:
We've recently got a new Server in. The server has 16Gb of RAM, 8 cpus etc We now have a choice of sticking with Windows 2000 Advanced Server or going with Windows 2003 Enterprise edition. ...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
5
by: JayCallas | last post by:
I have a requirement where I need to perform a query for position information. But for some types of entries, I need to "expand" the row to include additional position rows. Let me explain with an...
5
by: sinister | last post by:
I'm starting a database/web interface project, using Linux and postgresql. I've programmed in PHP4 in the past, and for this new project am unsure whether to use PHP4 or PHP5. My main concerns...
42
by: kenneth.m.mcdonald | last post by:
First, I don't intend this to be a flame war, please. Python and Ruby are the only two languages I'd willingly work in (at least amongst common languages), and TurboGears and Rails seem roughly...
1
by: Doogie | last post by:
I'm looking for some good reading material on the pros/cons of using the Session object and was wondering if anyone could point me in the right direction?
62
by: estherschindler | last post by:
This is part of a series examining the strengths and weaknesses of various scripting languages, with particular attention to enterprise (read: big company) use. You Used Python to Write WHAT?...
3
by: ziycon | last post by:
What would be the pros/cons of turning off error warnings in the website pages like below? What are peoples opinions on this approach? <?php error_reporting(0); ?>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.