How to create an array of objects?
-
i am developing an sms gateway application. I have a configuration text file which i have to read from the application and configure the connected modems according to it. After configuring the modems i have to save the configured modem as an object to an array/arraylist. So next time whenver i want the modem to do something i call the object from the array.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Drawing;namespace SMSTest
{
class SMSModem
{public ArrayList PortNameContainer = new ArrayList(); public ArrayList BaudRateContainer = new ArrayList(); public ArrayList DataBitContainer = new ArrayList(); public ArrayList PhoneNumberContainer = new ArrayList(); public ArrayList SMSCetreNoContainer = new ArrayList(); SerialPort serialPort1 = new SerialPort(); private string config\_file = "C:/config.txt"; // public string PhoneNumber; private string ServiceCentreNo; public int NumberOfLines = 0; public bool ModemConfig() { try { string line; TextReader tr = new StreamReader(config\_file); System.IO.StreamReader objReader; objReader = new System.IO.StreamReader(config\_file); while ((line = tr.ReadLine()) != null) { NumberOfLines++; } string\[\] ListLines = new string\[NumberOfLines\]; for (int i = 0; i < NumberOfLines; i++) { ListLines\[i\] = objReader.ReadLine(); string\[\] values = ListLines\[i\].Split(new char\[\] { '$', '#' }); string\[\] PortSplit = values\[0\].Split(new char\[\] { ':', '#' }); string PortName = PortSplit\[1\]; //\*\*\*\*\*\*\*\*Reading Baud Rate\*\*\*\*\*\*\*\*\* string\[\] BaudSplit = values\[1\].Split(new char\[\] { ':', '#' }); int BaudRate = Convert.ToInt32(BaudSplit\[1\]); //\*\*\*\*\*\*READING DATA BITS\*\*\*\*\*\*\*\*\*\* string\[\] BitsSplit = values\[2\].Split(new char\[\] { ':', '#' }); int DataBits = Convert.ToInt32(BitsSplit\[1\]); //\*\*\*\*\*\*\*\*REA
-
i am developing an sms gateway application. I have a configuration text file which i have to read from the application and configure the connected modems according to it. After configuring the modems i have to save the configured modem as an object to an array/arraylist. So next time whenver i want the modem to do something i call the object from the array.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.ComponentModel;
using System.Data;
using System.Drawing;namespace SMSTest
{
class SMSModem
{public ArrayList PortNameContainer = new ArrayList(); public ArrayList BaudRateContainer = new ArrayList(); public ArrayList DataBitContainer = new ArrayList(); public ArrayList PhoneNumberContainer = new ArrayList(); public ArrayList SMSCetreNoContainer = new ArrayList(); SerialPort serialPort1 = new SerialPort(); private string config\_file = "C:/config.txt"; // public string PhoneNumber; private string ServiceCentreNo; public int NumberOfLines = 0; public bool ModemConfig() { try { string line; TextReader tr = new StreamReader(config\_file); System.IO.StreamReader objReader; objReader = new System.IO.StreamReader(config\_file); while ((line = tr.ReadLine()) != null) { NumberOfLines++; } string\[\] ListLines = new string\[NumberOfLines\]; for (int i = 0; i < NumberOfLines; i++) { ListLines\[i\] = objReader.ReadLine(); string\[\] values = ListLines\[i\].Split(new char\[\] { '$', '#' }); string\[\] PortSplit = values\[0\].Split(new char\[\] { ':', '#' }); string PortName = PortSplit\[1\]; //\*\*\*\*\*\*\*\*Reading Baud Rate\*\*\*\*\*\*\*\*\* string\[\] BaudSplit = values\[1\].Split(new char\[\] { ':', '#' }); int BaudRate = Convert.ToInt32(BaudSplit\[1\]); //\*\*\*\*\*\*READING DATA BITS\*\*\*\*\*\*\*\*\*\* string\[\] BitsSplit = values\[2\].Split(new char\[\] { ':', '#' }); int DataBits = Convert.ToInt32(BitsSplit\[1\]); //\*\*\*\*\*\*\*\*REA
Your post is broken and hard to read. Please edit it and make it readable.
Aghosh Babu wrote:
i want to create an array of modem objects
Create a class, say
Modem
with all required properties and put it in aList<Modem>
other than arraylist.Navaneeth How to use google | Ask smart questions
-
Your post is broken and hard to read. Please edit it and make it readable.
Aghosh Babu wrote:
i want to create an array of modem objects
Create a class, say
Modem
with all required properties and put it in aList<Modem>
other than arraylist.Navaneeth How to use google | Ask smart questions
-
:)
Navaneeth How to use google | Ask smart questions
-
:)
Navaneeth How to use google | Ask smart questions
:confused::confused:
-
:confused::confused:
pls tell me how to create an array of objects in general? and how to call the objects later??
-
pls tell me how to create an array of objects in general? and how to call the objects later??
Aghosh Babu wrote:
pls tell me how to create an array of objects
object[] objArray = {new object(),new object()};
You access it with an indexer. Like
object obj1 = objArray[0]
. These all are basics and looks like you need a C# book. :)
Navaneeth How to use google | Ask smart questions
-
Aghosh Babu wrote:
pls tell me how to create an array of objects
object[] objArray = {new object(),new object()};
You access it with an indexer. Like
object obj1 = objArray[0]
. These all are basics and looks like you need a C# book. :)
Navaneeth How to use google | Ask smart questions
I am not an expert.. this is my univ project! ;P
-
I am not an expert.. this is my univ project! ;P
-
Aghosh Babu wrote:
this is my univ project!
Then you've learnt nothing, choose another career path.
thanks for the advice! unfortunately i havn't born as a programmer ;P
-
thanks for the advice! unfortunately i havn't born as a programmer ;P
<pre> i am developing an sms gateway application</pre> If ur not programmer then how you develop that gateway. :sigh: But Here is the Solution
ArrayList arrObj = new ArrayList();
arrObj.Add(YourObject);foreach(object o in arrObj)
{
if(o is YourObjectClass)
{
//Use this object
}
}WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
-
Aghosh Babu wrote:
this is my univ project!
Then you've learnt nothing, choose another career path.