473,406 Members | 2,816 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,406 software developers and data experts.

C# APP - Create Multiple Instances of a class a runtime

1
Hi guys,

I am new to C# and a have a question around class instances.

I have a class, Pizza. To create an instance I would use:

Expand|Select|Wrap|Line Numbers
  1. Pizza pizza1 = new Pizza("Cheese");
Lets suppose I wanted to create a new instance of a pizza when a customer makes an order at runtime.

How can I create a Pizza instance at runtime without create the instances first (because i dont know how many pizzas would be ordered)?

Ideally i would like the instances the take a name I supply at runtime (e.g from a string)
Mar 14 '08 #1
1 2969
Plater
7,872 Expert 4TB
Well whenever the user orders a pizza say, you could create another instance of it in whatever code runs when they order a pizza.
A System.Collections object could be used to keep/hold (think an Array only you can keep adding to it with a .Add(myobject)) all the new instances you create.

There is also System.Reflection which would create an instance of an object from a string. I don't know much about it, so you would have to check msdn about it.
Mar 14 '08 #2

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

Similar topics

2
by: Markus Prediger | last post by:
Hi NG, I have an asp.net project that uses an vb6 com object for some database-manipulation (I cannot rewrite it in .net, sorry, its not my decision). I want it to be instanciated seperately...
1
by: Digital Fart | last post by:
hi I want to wrap the access to a sqlite database in an object. So i can create multiple instances of this wrapper with base code to get data out of the sqlite database. But i want to make...
6
by: Bugs | last post by:
Does anyone have any recommendations on the best way to create multiple instances of the same class when the final number of instances is unknown? For example, I have a class and based on some...
6
by: Savante | last post by:
I have been writing a datalogging application. It reads in double's into a database. I want to be able to click on a row in a database (holds name of variable and also current value of variable)...
1
by: jigsmshah | last post by:
how can i create one more instance of windows service on the same sysyem? I have one service already working,the new requiremnt is to create one more instance of the same service on the same system....
1
by: =?Utf-8?B?UGFkYW0=?= | last post by:
I created a user conrolt in C# and want to create multiple instance (one by one) of usercontrol onclick of button. if i hard code in .aspx page like <%@ Register...
3
by: yogeshtiwarijbp | last post by:
Hi All I have a resume upload application which is a web application. I have to done load testing on that application. For that i have to create a windows application and create multiple instances...
42
sueb
by: sueb | last post by:
Is there a way to specify that selecting a Switchboard option (that brings up a form) creates another instance of that form v. changing focus to the existing one?
1
by: manontheedge | last post by:
I'm trying to create multiple instances of a class dynamically. For example ... Class A { ... ... };
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...
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
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...
0
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...
0
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...
0
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,...
0
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...

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.