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

Custom class array syntax help



Hello, I know C++ but am new to C# so bear with me.

I want to create an array of my own class. Something like this:
///////////////////////////////////////
class CLoginInfo
{
public string name;
public string id;
public string pw;

public CLoginInfo()//constructor
{
this.name = "";//initialize
this.id = "";
this.pw = "";
}
}
private CLoginInfo[] m_logins;

public Form1()
{
m_logins = new CLoginInfo[3];
...
m_logins[0].name = "Mick";//???? exception!!!
m_logins[0].id = "MicksID";
m_logins[0].pw = "MicksPW";
...
m_logins[1].name = "Joe";
m_logins[1].id = "JoesID";
m_logins[1].pw = "JoesPW";
...
}
///////////////////////////////////////

This compiles but I get the runtime exception error: "Object reference
not set to an instance of an object."

What is the proper syntax?

Also is there a way to dynamically change the size of the array?

Thank you for any suggestions,
Mick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
1 6008
By doing m_logins = new CLoginInfo[3];
You actually declare an array that refers to CLoginInfo instances. You do
not create the objects.
After your creation, if you look at the content of m_logins[0], it will be
null.

You habe to create the 3 objects and assign them to your array.

Joaé
"Mick" <no*****@nowhere.com> a écrit dans le message de
news:uN****************@TK2MSFTNGP11.phx.gbl...


Hello, I know C++ but am new to C# so bear with me.

I want to create an array of my own class. Something like this:
///////////////////////////////////////
class CLoginInfo
{
public string name;
public string id;
public string pw;

public CLoginInfo()//constructor
{
this.name = "";//initialize
this.id = "";
this.pw = "";
}
}
private CLoginInfo[] m_logins;

public Form1()
{
m_logins = new CLoginInfo[3];
...
m_logins[0].name = "Mick";//???? exception!!!
m_logins[0].id = "MicksID";
m_logins[0].pw = "MicksPW";
...
m_logins[1].name = "Joe";
m_logins[1].id = "JoesID";
m_logins[1].pw = "JoesPW";
...
}
///////////////////////////////////////

This compiles but I get the runtime exception error: "Object reference
not set to an instance of an object."

What is the proper syntax?

Also is there a way to dynamically change the size of the array?

Thank you for any suggestions,
Mick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2

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

Similar topics

3
by: Neil Zanella | last post by:
Hello, In Python, classes are objects. But there is no way to custom print a class object. This would require some syntax such as the one commented out below: With the current "foo =...
7
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service...
5
by: Sadeq | last post by:
Is it possible to define custom attributes for arrays? And if so, how can I retrieve them? I mean I want to define sth like: int MyArray; and then retrieve the value of the custom...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
1
by: Gene | last post by:
I would like to know if the following is even possible with the visual studio.net Setup and Deployment project. 1. During the deployment after creation of application directory the setup needs...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
27
by: Keith Wilby | last post by:
I've been trying to get my head around custom classes by following the example in the Visual Basic Language Developer's Handbook by Sybex. I think I have a handle on what they're about, albeit a...
2
by: trialproduct2004 | last post by:
Hi all, I am having application in whihc i am inserting menuitem dynamically. When i add menuitem to mainmenu, i want to pass extra parameter to eventargs. So what i did is derived class from...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
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...

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.