473,785 Members | 2,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Gott a go",2);
RecordSet Track3 = new RecordSet("My life",3);
RecordSet Track4 = new RecordSet("Amaz ing",4);

Data d = new Data();

d.RecordAdd(Tra ck1);
d.RecordAdd(Tra ck2);
d.RecordAdd(Tra ck3);
d.RecordAdd(Tra ck4);

//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)strReco rds[0];

d.GetRec2(strRe cords);

Nov 17 '05 #1
7 1610
Matt <me*******@Hotm ail.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("Gott a go",2);
RecordSet Track3 = new RecordSet("My life",3);
RecordSet Track4 = new RecordSet("Amaz ing",4);

Data d = new Data();

d.RecordAdd(Tra ck1);
d.RecordAdd(Tra ck2);
d.RecordAdd(Tra ck3);
d.RecordAdd(Tra ck4);

//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)strReco rds[0];

d.GetRec2(strRe cords);


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.co m>
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.WriteLi ne("Records: " + str);
}
}

Nov 17 '05 #3
Matt <me*******@Hotm ail.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.co m>
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(RecordS et[] Recs)
{
foreach (RecordSet Rec in Recs)
{
Console.WriteLi ne("Records: " + Rec);
}
}

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

d.GetRec2(recor ds);

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

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

Data d = new Data();
d.RecordAdd(Tra ck1);
d.RecordAdd(Tra ck2);
d.RecordAdd(Tra ck3);
d.RecordAdd(Tra ck4);
d.RecordAdd(Tra ck5);

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

d.GetRec2(recor ds);

Console.WriteLi ne(records[1]);

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

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

d.GetRec2(recor ds);


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.co m>
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.Collecti ons;
class RecordSet
{
private string Item;
private int val;
public RecordSet(strin g 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(Recor dSet r)
{
List.Add(r);
}
public void GetRec2(RecordS et[] Recs)
{
foreach (RecordSet Rec in Recs)
{
Console.WriteLi ne("Records: " + Rec);
}
}
public static void Main(string[] args)
{
RecordSet Track1 = new RecordSet("Its raining",1);
RecordSet Track2 = new RecordSet("Amaz ing in the wild",2);
RecordSet Track3 = new RecordSet("Amaz ing in the milg",3);

Data d = new Data();

d.RecordAdd(Tra ck1);
d.RecordAdd(Tra ck2);
d.RecordAdd(Tra ck3);

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

Nov 17 '05 #8

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

Similar topics

5
6760
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 clearly be the most efficient way to do it, but it only works on a copy of the original array and not the original (which is counter intuitive in my estimation). Using each doesn't work consistently either. Not only that, it's unduly complex for...
7
2727
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) {0,1,2,3} Since arrays start at 0 (I am thinking)
2
2460
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 greatest! I am trying to sum specific values in my arrays (or the price portions of the arrays). I have tried every imaginable way with the array_sum command and nothing has worked for me! Here is what my cookie information looks like after I put 2...
4
2249
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 values are arrays and the echo comes out like: subjectone = Array subjecttwo = Array
1
7696
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 is a better way to achieve it for(i=0;i<arrayA.length;i++){ for(j=0;j<arrayB.length;j++){ if(arrayA==arrayB)
2
7053
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, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
2
5883
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 place...can anyone help me?? i didnt made anything in the VALUES (unless the POST ), because i bet the error is there (yes, the arrays are missing): $sql = "INSERT INTO dgplanets ( ID, coords , player name , alliance , name , ground , orbit ,...
3
2105
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 in the conditional IF statement is only happening against the first value --$link-- in the array --@route-- I want the comparison between the two arrays to repeat for every value in the first array @route. Appreciate any guidance or ideas...
5
1575
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://" + document.location.host + "/sampleiws/images/usa/ 1metercalif.ecw", "ecwp://" + document.location.host + "/sampleiws/images/australia/ parramatta.ecw";
1
3010
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> readFile()throws Exception { String n = null; // List draw; try{ BufferedReader fh = new BufferedReader(new FileReader("myInputFile.txt")); while(true){
0
9480
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
10325
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
10148
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
10091
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
9950
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...
1
7499
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
6740
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();...
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.