----------------------------------------------------------- New Message on BDOTNET
----------------------------------------------------------- From: Satheshraman Message 2 in Discussion Hi Balasubramaian, ChildItems chk = new ChildItems(); chk.name = "mouse"; chk.qty = "10"; ord.ChildItem[0] = chk; // you are assigning reference to null object. Instead of this please change the code like below ord.ChildItem = new ChildItems[1]; ord.ChildItem[0] = chk; string na = ord.ChildItem[0].name; string q = ord.ChildItem[0].qty; po.OrderedItems[0] = ord; Regards, Satheshkumar.Raman To: [email protected] From: [EMAIL PROTECTED] Subject: Assigning value to class array object Date: Thu, 27 Sep 2007 12:35:43 -0700 <META content="Microsoft SafeHTML" name=Generator> <STYLE> ExternalClass EC_ThmFgColumnHeader, .ExternalClass EC_A.FrameLink, ExternalClass EC_A.HeaderLink, .ExternalClass EC_A.FooterLink, ExternalClass EC_A.LgtCmd, .ExternalClass EC_A.MSNLink {color:#FFFFFF;} ExternalClass EC_ThmFgTitleLightBk {color:#FF6600;} ExternalClass EC_ThmFgSmallLight {color:#ff0000;} ExternalClass EC_ThmFgNavLink, .ExternalClass EC_A.NavLink, ExternalClass EC_A.ChildLink:hover {color:#666699;} ExternalClass EC_ThmFgInactiveText, .ExternalClass EC_A.SystemLink {color:#666666;} ExternalClass EC_ThmFgFrameTitle {color:#FFFFCC;} ExternalClass EC_ThmFgTitleDarkBk, .ExternalClass EC_A.NavLink:hover, ExternalClass EC_A.TitleLink {color:#CC6600;} ExternalClass EC_ThmFgMiscText, .ExternalClass EC_A.Cat, .ExternalClass EC_A.SubCat {color:#336699;} ExternalClass EC_ThmFgCommand, .ExternalClass EC_A.Command, ExternalClass EC_A.LargeCommand, .ExternalClass EC_A.MsgLink {color:#003366;} ExternalClass EC_ThmFgHeader {color:#333333;} ExternalClass EC_ThmFgStandard, .ExternalClass EC_A.SystemLink:hover, ExternalClass EC_A.SubLink, .ExternalClass EC_A.ChildLink, ExternalClass EC_A.StdLink, .ExternalClass EC_SELECT.Standard {color:#000000;} ExternalClass EC_ThmFgDivider {color:#CCCCCC;} ExternalClass EC_ThmBgStandard {background-color:#FFFFFF;} ExternalClass EC_ThmBgUnknown1 {background-color:#FF6600;} ExternalClass EC_ThmBgFraming {background-color:#666699;} ExternalClass EC_ThmBgUnknown2 {background-color:#666666;} ExternalClass EC_ThmBgHighlightDark {background-color:#FFFFCC;} ExternalClass EC_ThmBgHighlightLight, .ExternalClass #EC_idToolbar, ExternalClass #EC_tbContents {background-color:#FFFFE8;} ExternalClass EC_ThmBgTitleDarkBk {background-color:#F1F1F1;} ExternalClass EC_ThmBgAlternate {background-color:#ECF1F6;} ExternalClass EC_ThmBgUnknown3 {background-color:#CCCCFF;} ExternalClass EC_ThmBgDivider {background-color:#CCCCCC;} ExternalClass EC_ThmBgHeader {background-color:#9999CC;} ExternalClass EC_ThmBgLinks {background-color:#8696C9;} ExternalClass EC_ThmBgSharkBar {background-color:#8696C9;} ExternalClass EC_ThmBgGlobalNick {background-color:#9394A9;} ExternalClass EC_calfgndcolor {color:#E00505;} ExternalClass EC_calbgndcolor {color:#E00505;} </STYLE> New Message on BDOTNET Assigning value to class array object Reply Reply to Sender Recommend Message 1 in Discussion From: Balasubramanian1 Hi All We have three classes Purchaseorder , orderedItem and childItems. In purchase class we have array of ordereditem object. In orderItem class we have array of ChildItems. when we try to assign value to child item we are getting error,object reference not set. how to assign childitem object to orderitem . See the below code. if you have any other way plz suggess me. I am getting error in Bold Code. public class PurchaseOrder { public Address ShipTo; public string OrderDate; /* The XmlArrayAttribute changes the XML element name from the default of "OrderedItems" to "Items". */ [XmlArrayAttribute("Items")] public OrderedItem[] OrderedItems; public decimal SubTotal; public decimal ShipCost; public decimal TotalCost; } public class Address { /* The XmlAttribute instructs the XmlSerializer to serialize the Name field as an XML attribute instead of an XML element (the default behavior). */ [XmlAttribute] public string Name; public string Line1; /* Setting the IsNullable property to false instructs the XmlSerializer that the XML attribute will not appear if the City field is set to a null reference. */ [XmlElementAttribute(IsNullable = false)] public string City; public string State; public string Zip; } public class ChildItems { public string name; public string qty; } public class OrderedItem { public string ItemName; public string Description; public decimal UnitPrice; public int Quantity; public decimal LineTotal; [XmlArrayAttribute("ChildItem")] public ChildItems[] ChildItem; /* Calculate is a custom method that calculates the price per item, and stores the value in a field. */ public void Calculate() { LineTotal = UnitPrice * Quantity; } } public class Test { public static void Main() { // Read and write purchase orders. Test t = new Test(); t.CreatePO("po.xml"); t.ReadPO("po.xml"); } private void CreatePO(string filename) { // Create an instance of the XmlSerializer class; // specify the type of object to serialize. XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrder)); TextWriter writer = new StreamWriter(filename); PurchaseOrder po = new PurchaseOrder(); // Create an address to ship and bill to. Address billAddress = new Address(); billAddress.Name = "Teresa Atkinson"; billAddress.Line1 = "1 Main St."; billAddress.City = "AnyTown"; billAddress.State = "WA"; billAddress.Zip = "00000"; po.ShipCost = (decimal)23.6; po.ShipTo = billAddress; po.SubTotal = (decimal)67.5; po.TotalCost = (decimal)45.6; po.OrderDate = "OrderDate"; OrderedItem ord = new OrderedItem(); ord.ItemName = "test"; ord.LineTotal = 56; ord.Quantity = 3; ord.UnitPrice = 56; ord.Description = "desx"; ChildItems chk = new ChildItems(); chk.name = "mouse"; chk.qty = "10"; ord.ChildItem[0] = chk; po.OrderedItems[0] = ord; Regards Bala S View other groups in this category. To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. Need help? If you've forgotten your password, please go to Passport Member Services. For other questions or feedback, go to our Contact Us page. If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. Remove my e-mail address from BDOTNET. Call friends with PC-to-PC calling -- FREE Try it now! ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/bdotnet/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]
