I have two .cs files and I am trying to have them interact in the project.
One is Form1.cs and the other is Define.cs
Form1 has code that creates a type "Cars"
I instantiate an array of type Test with properties
public static Cars[] myCar = new Cars[17];
public class Cars
{
public string Wheels;
...
}
Now, I have 17 cars that have specific properties like one has Cars.Wheels =
Chrome, etc.
However, I don't want to waste the space in my Form1.cs file, AND I may want
to use the 17 car's info in other programs. Therefore, I decided to make a
separate .cs file called Define to simply have the info for these cars.
However, when I try to call the Define file's constructor, it stops on the
first assignment line:
Cars[0].Wheels = "Chrome";
and says "Object reference not set to an instance of an object"
why is this. I feel that i have tried alll I can. I think I am missing
some understanding here. Could someone please help me? 7 1540
You know, that problem seems to occur when I instantiate an array of type
Cars.
"mb" <mm@hotmail.com > wrote in message
news:OU******** ******@TK2MSFTN GP09.phx.gbl... I have two .cs files and I am trying to have them interact in the project.
One is Form1.cs and the other is Define.cs
Form1 has code that creates a type "Cars"
I instantiate an array of type Test with properties
public static Cars[] myCar = new Cars[17];
public class Cars { public string Wheels; ... }
Now, I have 17 cars that have specific properties like one has Cars.Wheels
= Chrome, etc. However, I don't want to waste the space in my Form1.cs file, AND I may
want to use the 17 car's info in other programs. Therefore, I decided to make
a separate .cs file called Define to simply have the info for these cars. However, when I try to call the Define file's constructor, it stops on the first assignment line:
Cars[0].Wheels = "Chrome";
and says "Object reference not set to an instance of an object"
why is this. I feel that i have tried alll I can. I think I am missing some understanding here. Could someone please help me?
when you use
Classtype[] myobjects = new Classtype[number];
it creates an array with references set to null
you will need to use
myobjects[1] = new Classtype(const ructor)
if the type is a value type then the array is initialized but in this case
its a reference type and you will need to initialize it
--
Regards,
Hermit Dave
( http://hdave.blogspot.com)
"mb" <mm@hotmail.com > wrote in message
news:O3******** ******@TK2MSFTN GP15.phx.gbl... You know, that problem seems to occur when I instantiate an array of type Cars.
"mb" <mm@hotmail.com > wrote in message news:OU******** ******@TK2MSFTN GP09.phx.gbl... I have two .cs files and I am trying to have them interact in the
project. One is Form1.cs and the other is Define.cs
Form1 has code that creates a type "Cars"
I instantiate an array of type Test with properties
public static Cars[] myCar = new Cars[17];
public class Cars { public string Wheels; ... }
Now, I have 17 cars that have specific properties like one has
Cars.Wheels = Chrome, etc. However, I don't want to waste the space in my Form1.cs file, AND I may want to use the 17 car's info in other programs. Therefore, I decided to
make a separate .cs file called Define to simply have the info for these cars. However, when I try to call the Define file's constructor, it stops on
the first assignment line:
Cars[0].Wheels = "Chrome";
and says "Object reference not set to an instance of an object"
why is this. I feel that i have tried alll I can. I think I am missing some understanding here. Could someone please help me?
so, instead of:
Classtype[] myobjects = new Classtype[number];
I need to use:
myobjects[0] = new Classtype(const ructor);
myobjects[1] = new Classtype(const ructor);
....
Is that right? Or do I use both?
Also, is it a reference because it is a type from another .cs file?
"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. when you use
Classtype[] myobjects = new Classtype[number]; it creates an array with references set to null you will need to use
myobjects[1] = new Classtype(const ructor)
if the type is a value type then the array is initialized but in this case its a reference type and you will need to initialize it
--
Regards,
Hermit Dave (http://hdave.blogspot.com) "mb" <mm@hotmail.com > wrote in message news:O3******** ******@TK2MSFTN GP15.phx.gbl... You know, that problem seems to occur when I instantiate an array of
type Cars.
"mb" <mm@hotmail.com > wrote in message news:OU******** ******@TK2MSFTN GP09.phx.gbl... I have two .cs files and I am trying to have them interact in the project. One is Form1.cs and the other is Define.cs
Form1 has code that creates a type "Cars"
I instantiate an array of type Test with properties
public static Cars[] myCar = new Cars[17];
public class Cars { public string Wheels; ... }
Now, I have 17 cars that have specific properties like one has Cars.Wheels = Chrome, etc. However, I don't want to waste the space in my Form1.cs file, AND I
may want to use the 17 car's info in other programs. Therefore, I decided to make a separate .cs file called Define to simply have the info for these
cars. However, when I try to call the Define file's constructor, it stops on the first assignment line:
Cars[0].Wheels = "Chrome";
and says "Object reference not set to an instance of an object"
why is this. I feel that i have tried alll I can. I think I am
missing some understanding here. Could someone please help me?
"mb" <mm@hotmail.com > wrote in message
news:uW******** ******@TK2MSFTN GP10.phx.gbl... so, instead of: Classtype[] myobjects = new Classtype[number];
I need to use:
myobjects[0] = new Classtype(const ructor); myobjects[1] = new Classtype(const ructor); ...
Is that right? Or do I use both?
Both.
new Classtype[number] creates the array
new Classtype(const ructor) creates the individual objects which you then
store in the array. Also, is it a reference because it is a type from another .cs file?
what do you mean by that?
I original post mentions that I want to store all of the 17 cars properties
in a seperate .cs file so I could reuse it. The first .cs file has the Cars
class, then I initiallize all the cars in another .cs file. Maybe this
doesn't make a difference.
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:O$******** ******@TK2MSFTN GP11.phx.gbl... "mb" <mm@hotmail.com > wrote in message news:uW******** ******@TK2MSFTN GP10.phx.gbl... so, instead of: Classtype[] myobjects = new Classtype[number];
I need to use:
myobjects[0] = new Classtype(const ructor); myobjects[1] = new Classtype(const ructor); ...
Is that right? Or do I use both?
Both.
new Classtype[number] creates the array new Classtype(const ructor) creates the individual objects which you then store in the array.
Also, is it a reference because it is a type from another .cs file?
what do you mean by that?
what you need to do is this
int arraylength = 17;
ClassType[] myCT = new ClassType[arraylength]; // this initializes the array
with null references
myCT[0] = new ClassType(the parameters list for contructor); // this creates
a new instance inplace of the null reference earlier.
// you want to add second car
myCT[1] = new ClassType(secon d set of params)
-------------------------------------------
that is one way the other way would be to create you own Custom collection
class which has an array as internal member.
Create your add method which will add the newly created car object to the
collection. With arraylist you do not have to worry about the length and you
create the object when you need it and add it to the colleciton
hope this help
--
Regards,
Hermit Dave
( http://hdave.blogspot.com)
"mb" <mm@hotmail.com > wrote in message
news:u5******** ******@TK2MSFTN GP15.phx.gbl... I original post mentions that I want to store all of the 17 cars
properties in a seperate .cs file so I could reuse it. The first .cs file has the
Cars class, then I initiallize all the cars in another .cs file. Maybe this doesn't make a difference. "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:O$******** ******@TK2MSFTN GP11.phx.gbl... "mb" <mm@hotmail.com > wrote in message news:uW******** ******@TK2MSFTN GP10.phx.gbl... so, instead of: Classtype[] myobjects = new Classtype[number];
I need to use:
myobjects[0] = new Classtype(const ructor); myobjects[1] = new Classtype(const ructor); ...
Is that right? Or do I use both?
Both.
new Classtype[number] creates the array new Classtype(const ructor) creates the individual objects which you then store in the array.
Also, is it a reference because it is a type from another .cs file?
what do you mean by that?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vic |
last post by:
Dear All,
I found this code snippet on this list (taken from a nice webpage of a
courteous fellow), which I used to filter a form on a combo box. I
wanted to repeat the same code to have an additional combo control
doing a different filtering on the same form, and simply copied the
code below and changed the appropriate combo names....
|
by: Aaron Ackerman |
last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried
everything and I am at a loss. The using goes into add mode with the add
button adds his data then updates with the update button, seems simple.
I am using ALL visual controls (supposedly to simplify things. If I was not
using the visual controls and calling an ExecuteNonQuery...
|
by: Phil Certain |
last post by:
Hi,
Relative newbie to .Net but experienced with classic ASP. I am trying
to create a simple business object to contain commonly used functions.
This is what I have done:
1 - Created a simple vb file containing:
Imports System.Data.SqlClient
Imports System.Web.HttpUtility
|
by: vvenk |
last post by:
Hello:
I have the following code:
Dim lsFilter As String = Nothing
Select Case rblStatus.SelectedItem.Value
Case "S"
lsFilter = String.Concat("D_STAT_CD_C = '", "N'")
Case "R"
lsFilter = String.Concat("D_STAT_CD_C <> '", "N'")
|
by: Steve |
last post by:
I have a gridview which uses an objectdatasource for its select and
delete.
The delete command uses the function below. The delete itself works but
the extra logic which requires parameters AccountDebitID and
AccountCreditID does not work.
'Delete a transaction
Sub deletetrans(ByVal transactionid As Integer, ByVal transactionamount
| |
by: watkinsdev |
last post by:
Hi,
I have created a mesh class in visual studio 6.0 c++.
I can create a device, render objects and can edit the objects by for
instancnce selecting a cluster of vertices and processing the vertices
and can do this multiple times on a sinlge vertex cluster.
The problem I have been encoutering is that, if I select a second
vertex...
|
by: shapper |
last post by:
Hello,
I am creating a class with a control. I compiled the class and used it
on an Asp.Net 2.0 web site page.
I can see the begin and end tags of my control (<oland </ol>) but
somehow the child controls (just a literal for testing) of my control
is not being added to the page.
Could someone tell me what am I doing wrong?
|
by: SirG |
last post by:
I'm looking for an explanation of why one piece of code works and
another does not. I have to warn you that this is the first piece of
Javascript I've ever written, so if there is a better way or a simpler
answer, by all means show me the light!
What I'm trying to do is refresh the page at a timed interval
( actually redirect the page... )...
|
by: Enkidu |
last post by:
Beginner question, sorry!
I am using indexers to access an array of StringBuilders in an instance
of a class:
Getting:
value = board1;
Setting:
board1 = value1 ;
|
by: DavidSeck.com |
last post by:
Hi,
I am working with the Facebook API right now, an I have kind of a
problem, but I don't know what I am doing wrong.
So I have a few arrays, f.ex.:
User albums:
array(2) {
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |