[Year 12 SofDev] C# - Adding data to an Array from user input

Hem, Lony L hem.lony.l at edumail.vic.gov.au
Tue Feb 7 09:37:15 AEDT 2017


Hi Darren

I haven’t used this very often in c# but something equivalent would be

Array.Resize<T>(ref T myarray, int size)

Eg

Array.Resize<cars>(ref myArray, 20) // set size of array to 20

Alternatively I would use

var  myCars = new List<cars>();
myCars.Add(new cars());
myCars.Last<cars>().id = “jkhj”;

var myarray = myCars.ToArray<cars>(); //if need array

Regards Lony

From: sofdev-bounces at edulists.com.au [mailto:sofdev-bounces at edulists.com.au] On Behalf Of Darren Scott
Sent: Tuesday, 7 February 2017 8:33 AM
To: Year 12 Software Development Teachers' Mailing List <sofdev at edulists.com.au>
Subject: Re: [Year 12 SofDev] C# - Adding data to an Array from user input

VB has a Redim command … does C# ?

Something like this?

ReDim Preserve thesecars(0 To thiscar)          ' keep the data, add one to the array of cars
        thesecars(thiscar) = New cars                   ' make a new car
        With thesecars(thiscar)                         ' get info from screen into thiscar
            .id = Val(lblID.Text)
            .make = txtMake.Text
            .model = txtModel.Text
        End With

It’s probably not the cleanest solution …

Darren


[cid:image002.png at 01D28124.D075EA00]

Darren Scott
Teacher
Catholic College Bendigo

'Opening the Doors of Mercy'

La Valla (Yrs 7-9): Ph: 03 5449 3466

Coolock (Yrs 10-12): Ph: 03 5445 9100

Finance Office: Ph: 03 5445 9191




From: sofdev-bounces at edulists.com.au<mailto:sofdev-bounces at edulists.com.au> [mailto:sofdev-bounces at edulists.com.au] On Behalf Of Cooper, Michael J
Sent: Monday, February 6, 2017 4:35 PM
To: Year 12 Software Development Teachers' Mailing List <sofdev at edulists.com.au<mailto:sofdev at edulists.com.au>>
Subject: Re: [Year 12 SofDev] C# - Adding data to an Array from user input

Thanks Ben the list methods seem like a much cleaner way to do it

Michael Cooper
ICT Co-ordinator & Network Support

[id:image001.png at 01D2440D.0D6FCCA0]
braybrooksc.vic.edu.au<http://www.Braybrooksc.vic.edu.au>
Ph. 9312 2900


From: <sofdev-bounces at edulists.com.au<mailto:sofdev-bounces at edulists.com.au>> on behalf of Ben Hines <b.hines at ccg.vic.edu.au<mailto:b.hines at ccg.vic.edu.au>>
Reply-To: Year 12 Software Development Teachers' Mailing List <sofdev at edulists.com.au<mailto:sofdev at edulists.com.au>>
Date: Monday, 6 February 2017 at 2:46 pm
To: Year 12 Software Development Teachers' Mailing List <sofdev at edulists.com.au<mailto:sofdev at edulists.com.au>>
Subject: Re: [Year 12 SofDev] C# - Adding data to an Array from user input

Um,

The problem with arrays is that they are made with a fixed size.

You can easily have a textbox (or NumericInput) control, then a button that adds to the array. You will need to have a counter variable that keeps track of where you are in the array.

Or you could just use a List<T> which has methods for adding and removing from the list (List is just an array with lots of helpful functions that make it easier to use).

Hope that helps!

Regards,

Ben Hines


Ben Hines
Mathematics and ICT Teacher
Senior School - Waurn Ponds
(03)5241 1577

[Image removed by sender. hristian College Geelong]

[Image removed by sender.] Please consider the environment  before printing this email.
From: sofdev-bounces at edulists.com.au<mailto:sofdev-bounces at edulists.com.au> [mailto:sofdev-bounces at edulists.com.au] On Behalf Of Cooper, Michael J
Sent: Monday, 6 February 2017 12:58 PM
To: Year 12 Software Development Teachers' Mailing List <sofdev at edulists.com.au<mailto:sofdev at edulists.com.au>>
Subject: [Year 12 SofDev] C# - Adding data to an Array from user input

Hello fellow SD teachers,

C# coding question - what is the best way to allow a USER to enter data into an array using a GUI, not the console?

I’ve used InputBoxes and loops with Visual Basic, however InputBoxes don’t seem to be thing in C#, without adding the Microsoft.VisualBasic namepace.

I can add data to an array during design time easily enough, but I want the USER to be able to click on a button and be prompted to enter data, which then populates the array.

Or am I going about this the wrong way entirely and should be using another technique?

Michael Cooper
ICT Co-ordinator & Network Support

[cid:image009.png at 01D28124.D075EA00]
braybrooksc.vic.edu.au<http://www.Braybrooksc.vic.edu.au>
Ph. 9312 2900


IMPORTANT - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Training.


________________________________
Message protected by MailGuard: e-mail anti-virus, anti-spam and content filtering.
http://www.mailguard.com.au

Report this message as spam<https://console.mailguard.com.au/ras/1Qd3zTUEZM/1ibn1N2QYL7pAHC9BDIL3b/0>


This e-mail is intended for the use of the named individual or entity and may contain confidential and privileged information. Any dissemination, distribution or copying by anyone other than the intended recipient of this e-mail is strictly prohibited. If this e-mail has been received in error, then please notify Christian College or the author of this email immediately and destroy the original message. We have made every attempt to ensure this e-mail message is free from computer viruses however the attached files are provided on the basis that the user assumes all responsibility for use of the material transmitted. Views, opinions, etc. expressed reflect those of the author and not Christian College nor its associated companies and campuses which includes Eden Quality Services Pty Ltd.
________________________________
Message protected by MailGuard: e-mail anti-virus, anti-spam and content filtering.
http://www.mailguard.com.au



IMPORTANT - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Training.



IMPORTANT - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Training.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20170206/173f9589/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 8501 bytes
Desc: image002.png
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20170206/173f9589/image002-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.png
Type: image/png
Size: 9943 bytes
Desc: image006.png
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20170206/173f9589/image006-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.jpg
Type: image/jpeg
Size: 1457 bytes
Desc: image007.jpg
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20170206/173f9589/image007-0001.jpg 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image008.jpg
Type: image/jpeg
Size: 347 bytes
Desc: image008.jpg
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20170206/173f9589/image008-0001.jpg 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image009.png
Type: image/png
Size: 12483 bytes
Desc: image009.png
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20170206/173f9589/image009-0001.png 


More information about the sofdev mailing list