473,799 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to add all public records to a list

7 New Member
Hi

I was wondering if someone could let me know the best/correct way of doing this. I have a shortened example of code below:

In the beginning of the class I have a List of string containing all records. I have added each encapsulated field to the list in the set property and I need to maintain the order in the list. Is this way best way to do this? Or should I be doing this another cleaner way. I guess I’m asking for best coding techniques.

Thanks for any help

Expand|Select|Wrap|Line Numbers
  1. Class myclass()
  2. {
  3.  
  4.         public List<string> allRecords = new List<string>();
  5.  
  6.         // Basically i am appending whatever is set to the end of the string with all these
  7.  
  8.         string _recordStart = "HEADERSTART"; 
  9.         public string RecordStart
  10.         {
  11.             get { return _ recordStart; }
  12.             set 
  13.             { 
  14.                 _ recordStart += value;
  15.                 allRecords.Add(_recordStart);
  16.             }
  17.         }
  18.  
  19.         private string _example= "EXAMPLE_STRING"; 
  20.         public string Example
  21.         {
  22.             get { return _ example; }
  23.             set 
  24.             {
  25.                 _example+= value; 
  26.                 allRecords.Add(_example); 
  27.             }
  28.         }
  29.  
  30. // Many more encapsulated fields
  31.  
  32.         string _recordEnd= "HEADEREND"; 
  33.         public string HdrRecordEnd
  34.         {
  35.             get { return _ recordEnd; }
  36.             set 
  37.             { 
  38.                 _ recordEnd += value;
  39.                 allRecords.Add(_recordEnd);
  40.             }
  41.         }
  42. }
May 30 '09 #1
6 2762
tlhintoq
3,525 Recognized Expert Specialist
@tig2810
Lines 14 and 38. That space between the underscore and recordEnd is going to cause problems
May 30 '09 #2
tlhintoq
3,525 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1.         string _recordStart = "HEADERSTART"; 
  2.       public string RecordStart
  3.         {
  4.             get { return _recordStart; }
  5.             set 
  6.             { 
  7.                 _recordStart += value;
  8.                 allRecords.Add(_recordStart);
  9.             }
  10.         }
  11.  
Before ever setting RecordStart
_recordStart == "HEADERSTAR T"
Setting RecordStart the first time to "Bob"
_recordStart == "HEADERSTARTBob ".
allRecords[0] == "HEADERSTARTBob "
Setting RecordStart the second time to "Neil"
_recordStart == "BobNeil"
allRecords[0] == "HEADERSTARTBob "
allRecords[1] == "HEADERSTARTBob Neil"
Setting RecordsStart the third time to "Fred"
_recordStart == "HEADERSTARTBob NeilFred"
allRecords[0] == "HEADERSTARTBob "
allRecords[1] == "HEADERSTARTBob Neil"
allRecords[2] == "HEADERSTARTBob NeilFred"
Is that the behavior you are wanting?
May 30 '09 #3
tig2810
7 New Member
HI
I meant instead of 'allRecords.Add (_name); ' each time, should i be doing something like foreach fieldtype add to list etc?
May 30 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
I guess I'm not understanding the actual problem because it sounds like you are asking if there is a better way to add to a list than List.Add
I need to maintain the order in the list.
List.Add will add to the end of the list. The order of the list is the order in which you add. allRecords[0] will always be the first item added.

A List<> maintains it order unless you re-order it in some way, such as sorting.
May 30 '09 #5
tlhintoq
3,525 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1.         private string _example= "EXAMPLE_STRING"; 
  2.         public string Example
  3.         {
  4.             get { return _ example; }
  5.             set 
  6.             {
  7.                 _example+= value; 
  8.                 allRecords.Add(_example); 
  9.             }
  10.         }
  11.  
  12.  
You do realize that when you send a value such as "Main Street" to Example you are going to get this...

Before ever setting RecordStart
_recordStart == "HEADERSTAR T"
Setting RecordStart the first time to "Bob"
_recordStart == "HEADERSTARTBob ".
allRecords[0] == "HEADERSTARTBob "
Setting RecordStart the second time to "Neil"
_recordStart == "BobNeil"
allRecords[0] == "HEADERSTARTBob "
allRecords[1] == "HEADERSTARTBob Neil"
Setting RecordsStart the third time to "Fred"
_recordStart == "HEADERSTARTBob NeilFred"
allRecords[0] == "HEADERSTARTBob "
allRecords[1] == "HEADERSTARTBob Neil"
allRecords[2] == "HEADERSTARTBob NeilFred"
Setting Example to "Main Street"
_example = "EXAMPLE_STRING Main String"
_recordStart == "HEADERSTARTBob NeilFredEXAMPLE _STRINGMain String"
allRecords[0] == "HEADERSTARTBob "
allRecords[1] == "HEADERSTARTBob Neil"
allRecords[2] == "HEADERSTARTBob NeilFred"
allRecords[3] == "HEADERSTARTBob NeilFredEXAMPLE _STRINGMain String"
You're asking about best practices and frankly I just can't imagine any scenario where you would want this sort of thing. After adding only a few items you could have List elements that are hundreds of characters long consisting primarily of the previous element's value.
May 30 '09 #6
tig2810
7 New Member
the += is the required result for a weird EDI format. This is correct and was not the question. I'll look elsewhere. thanks anyway.
May 31 '09 #7

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

Similar topics

5
1729
by: yvan | last post by:
Approximately once a month, a client of ours sends us a bunch of comma-delimited text files which I have to clean up and then import into their MS SQL database. All last week, I was using a Cold Fusion script to upload the cleaned up files and then import the records they contained into the database, though obviously, the process took friggin' forever, and could have been done 500x quicker had I done it directly on the server. My SQL...
1
2099
by: Chris Uwins | last post by:
Hi there, i know theres a number of ways I can achieve this but want to know the best, (but still quite simple). Up until a year ago I never used Access but have designed a few databases for work. I am working on Access 2000. I have basic SQL/VB skills - and am pretty accomplished at putting the databases together. Anyway...I've created a database to keep track of "Dayworks" we are
14
3143
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them... (both are "Pascal Case" with no leading or trailing qualifiers). For example... I'll be modelling something, e.g. a computer, and I'll
2
1683
by: Robert Vasquez | last post by:
I have three classes. One (Class ObjectC) and two other classes (Class1 and Class2) that will hold instances of the ObjectC class. I would like to transfer an instance of OjectC from Class1 into Class2, while making sure that no resource leak occurs. Is the following the best way to hanlde this? Is there a more efficient way? public class ObjectC { public ObjectC() {
4
1759
by: Guy Noir | last post by:
Hello. Is there a pattern or best practice for the following scenario? I have a list of items I would like to compare. The number of items are decided at runtime. ObjectA, ObjectB, ObjectC......ObjectX I want to process a comparison for each of these projects. So, for
9
7910
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private List<as a property. Consider the example below, the class "ListTest" contains a private "List<>" called "strings" - it also provides a public method to add to that list,
5
1474
by: blisspikle | last post by:
I figure that someone good at dotnet can look at this and give me a clue on how to easily organize this code? If there is a unique identifier like "Publisher" with a bunch of "Book" that are published under them (I used the arraylist class in the publisher class). How should the code be organized, and how can the books properties like "Name" be easily called in the main code, or searched for in the main code?
5
12806
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for more incoming connections and does the BeginAccpet() again. It does an infinite loop this way. My question is: What is the best way to stop this? I thought about putting a boolean in there, but then what if it's still waiting for an incoming...
6
17864
by: kamsmartx | last post by:
I'm new to programming and need some help figuring out an algorithm. I need to design some kind of algorithm which will help us define capacity for one of our portfolios....here's the problem explained (also see attached example): 1. The graph defines total capacity, y-axis being $, x-axis being date/time. the bars on the graph represent individual items. 2. What I need to do is place the items on the graph in an optimized manner,...
0
10488
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...
0
10257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
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
10029
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
9077
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...
0
6808
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
5467
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...
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.