473,385 Members | 1,373 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,385 software developers and data experts.

Can i Box values in arrays

Is there a way to put my class vals to arrays !

RecordSet Track1 = new RecordSet("It aint fear",1);
RecordSet Track2 = new RecordSet("Gotta go",2);
RecordSet Track3 = new RecordSet("My life",3);
RecordSet Track4 = new RecordSet("Amazing",4);

Data d = new Data();

d.RecordAdd(Track1);
d.RecordAdd(Track2);
d.RecordAdd(Track3);
d.RecordAdd(Track4);

//Here i like put these on array so i can pass it as array is this do
able?
can i do boxing here to put Tracks on array ?
string [] strRecords = new String[5];
strRecords[0] = Track1;
string x = (string)strRecords[0];

d.GetRec2(strRecords);

Nov 17 '05 #1
7 1583
Matt <me*******@Hotmail.com> wrote:
Is there a way to put my class vals to arrays !

RecordSet Track1 = new RecordSet("It aint fear",1);
RecordSet Track2 = new RecordSet("Gotta go",2);
RecordSet Track3 = new RecordSet("My life",3);
RecordSet Track4 = new RecordSet("Amazing",4);

Data d = new Data();

d.RecordAdd(Track1);
d.RecordAdd(Track2);
d.RecordAdd(Track3);
d.RecordAdd(Track4);

//Here i like put these on array so i can pass it as array is this do
able?
can i do boxing here to put Tracks on array ?
string [] strRecords = new String[5];
strRecords[0] = Track1;
string x = (string)strRecords[0];

d.GetRec2(strRecords);


That's not boxing - that's converting records to strings. You could do
that if you defined conversion operators in RecordSet to and from
string, but I wouldn't recommend it. Why do the conversion to strings?
Why not just declare an array of RecordSets?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
i thought i had to convert.
That would work for me but evertime i did it i got error
How can i put these tracs on array so i can pass it to my method below.

string [] strRecords = new String[5];
strRecords[0] = Track1; // this did not work.
public void GetRec2(string[] Records)
{
foreach (string str in Records)
{
Console.WriteLine("Records: " + str);
}
}

Nov 17 '05 #3
Matt <me*******@Hotmail.com> wrote:
i thought i had to convert.
No, you can create an array of any type.
That would work for me but evertime i did it i got error
How can i put these tracs on array so i can pass it to my method below.

string [] strRecords = new String[5];
strRecords[0] = Track1; // this did not work.


No, it wouldn't, because Track1 isn't a string. Do:

RecordSet[] records = new RecordSet[5];
records[0] = Track1;

Then change the parameter for GetRec2 to be a RecordSet[].

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
This is what i have but i dont get the values ? what am i doing wrong
public void GetRec2(RecordSet[] Recs)
{
foreach (RecordSet Rec in Recs)
{
Console.WriteLine("Records: " + Rec);
}
}

RecordSet[] records = new RecordSet[5];
records[0] = Track1;
records[1] = Track1;

d.GetRec2(records);

Nov 17 '05 #5
Console.WriteLine(records[1]);
values is Recordset. Its not filling the array.

RecordSet Track1 = new RecordSet("Its raining",1);
RecordSet Track2 = new RecordSet("Amazing in the wild",2);
RecordSet Track3 = new RecordSet("Amazing in the milg",3);
RecordSet Track4 = new RecordSet("Amazing in the Sour",4);
RecordSet Track5 = new RecordSet("Amazing in the Hot",5);

Data d = new Data();
d.RecordAdd(Track1);
d.RecordAdd(Track2);
d.RecordAdd(Track3);
d.RecordAdd(Track4);
d.RecordAdd(Track5);

RecordSet[] records = new RecordSet[5];
records[0] = Track1;
records[1] = Track1;

d.GetRec2(records);

Console.WriteLine(records[1]);

Nov 17 '05 #6
Matt <me*******@Hotmail.com> wrote:
This is what i have but i dont get the values ? what am i doing wrong
public void GetRec2(RecordSet[] Recs)
{
foreach (RecordSet Rec in Recs)
{
Console.WriteLine("Records: " + Rec);
}
}

RecordSet[] records = new RecordSet[5];
records[0] = Track1;
records[1] = Track1;

d.GetRec2(records);


That is definitely passing the values.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7
Here it goes Jon

using System;
using System.IO;
using System.Collections;
class RecordSet
{
private string Item;
private int val;
public RecordSet(string item,int ival)
{
Item = item;
val = ival;
}
public string GetRecord
{
get{return Item;}
set{Item = value;}
}
}
class Data
{
ArrayList List = new ArrayList();
public void RecordAdd(RecordSet r)
{
List.Add(r);
}
public void GetRec2(RecordSet[] Recs)
{
foreach (RecordSet Rec in Recs)
{
Console.WriteLine("Records: " + Rec);
}
}
public static void Main(string[] args)
{
RecordSet Track1 = new RecordSet("Its raining",1);
RecordSet Track2 = new RecordSet("Amazing in the wild",2);
RecordSet Track3 = new RecordSet("Amazing in the milg",3);

Data d = new Data();

d.RecordAdd(Track1);
d.RecordAdd(Track2);
d.RecordAdd(Track3);

RecordSet[] records = new RecordSet[5];
records[0] = Track1;
records[1] = Track1;
d.GetRec2(records);
}
}

Nov 17 '05 #8

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

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
7
by: Chris Wertman | last post by:
I am so lost on this one. Dim Ary as Integer = New Integer(4) {0,1,2,3} FAILS with the error: Array initializer has 1 too few elements. So I try Dim Ary as Integer = New Integer(3)...
2
by: MrL8Knight | last post by:
I am building a simple shopping cart and I am having problems trying to add the costs of the items to generate a total cost. I am new at this so forgive me if my technical verbiage isn’t the...
4
by: Jack E Leonard | last post by:
I'm looping through the keys and values of a form submission using foreach($_POST as $key => $value) echo "$key = $value<br>"; No problems there. All works as expected. But seveal of the...
1
by: psmahesh | last post by:
Hi folks, I am comparing two arrays and removing matches from the second array from the first array. Can someone take a look at this code below and mention if this is okay and perhaps if there...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
2
by: blitzztriger | last post by:
Hello!! how do i insert values into mysql , after parsing a submiting textbox?? I made the arrays, so this should be a basic insertion of them in the db, but something is missing, or in the wrong...
3
by: hutch75 | last post by:
Question could also be asked, how to compare data between two arrays and perform an action (print cmd) everytime there is a match? The problem I'm having with the code below is that the comparison...
5
by: Pukeko | last post by:
Hi, this is an array that is used for a dropdown menu. var imageArray = new Array( "ecwp://" + document.location.host + "/massey/images/massey/ massey_07_fullres.ecw", "ecwp://" +...
1
by: cowboyrocks2009 | last post by:
Hi. I want to return values from multiple Arraylist. How can I do that ? later I want to use these values in another class. Can somebody help class myClass{ public ArrayList<Rectangle>...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.