Click here to Skip to main content
15,912,977 members
Home / Discussions / C#
   

C#

 
GeneralRe: XML file comparison output with node names Pin
Pete O'Hanlon25-Sep-18 20:38
mvePete O'Hanlon25-Sep-18 20:38 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan26-Sep-18 21:02
Raja Saravanan26-Sep-18 21:02 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan2-Oct-18 20:23
Raja Saravanan2-Oct-18 20:23 
GeneralRe: XML file comparison output with node names Pin
Pete O'Hanlon2-Oct-18 20:44
mvePete O'Hanlon2-Oct-18 20:44 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan3-Oct-18 17:14
Raja Saravanan3-Oct-18 17:14 
QuestionIssue with Land Registry Service reference.cs Pin
Member 1387432624-Sep-18 3:57
Member 1387432624-Sep-18 3:57 
AnswerRe: Issue with Land Registry Service reference.cs Pin
OriginalGriff24-Sep-18 4:08
mveOriginalGriff24-Sep-18 4:08 
AnswerRe: Issue with Land Registry Service reference.cs Pin
Richard Deeming24-Sep-18 7:56
mveRichard Deeming24-Sep-18 7:56 
Quote:
//THIS SECTION IS CAUSING ME AN ERROR
request.Product.Contact[1] = new Q1ContactType();
//request.Product.Contact = new Q1ContactType[1];
request.Product.Contact[0].Name = new Q3TextType();
request.Product.Contact[0].Name.Value = "Allen Jones";

request.Product.Contact[0].Communication = new Q1CommunicationType();
request.Product.Contact[0].Communication.Telephone.Value = "01925 938640";
//TO HERE

You're trying to store an element in the array before you've initialized the array. The request.Product.Contact array is null, so if you try to store anything in it, you'll get a NullReferenceException.

The code to initialize the array is on the following line, but you've commented it out.

You're also trying to store an item at index 1, and then modifying the item at index 0. Array indices are zero-based, and your commented-out line is creating an array of length 1, so the only valid index will be 0.
C#
request.Product.Contact = new Q1ContactType[1];
request.Product.Contact[0] = new Q1ContactType();
request.Product.Contact[0].Name = new Q3TextType();
request.Product.Contact[0].Name.Value = "Allen Jones";
request.Product.Contact[0].Communication = new Q1CommunicationType();
request.Product.Contact[0].Communication.Telephone.Value = "01925 938640";

If you're using a recent version of Visual Studio, you can simplify this code by using an initializer[^]:
C#
request.Product.Contact = new[]
{
    new Q1ContactType
    {
        Name = new Q3TextType
        {
            Value = "Allen Jones"
        },
        Communication = new Q1CommunicationType
        {
            Value = "01925 938640"
        }
    }
};




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Issue with Land Registry Service reference.cs Pin
glennPattonWork325-Sep-18 0:52
professionalglennPattonWork325-Sep-18 0:52 
QuestionHow to get last day of specific date Pin
thepast23-Sep-18 18:11
thepast23-Sep-18 18:11 
AnswerRe: How to get last day of specific date Pin
Mycroft Holmes23-Sep-18 20:32
professionalMycroft Holmes23-Sep-18 20:32 
AnswerRe: How to get last day of specific date Pin
Maciej Los23-Sep-18 21:17
mveMaciej Los23-Sep-18 21:17 
GeneralRe: How to get last day of specific date Pin
OriginalGriff23-Sep-18 21:38
mveOriginalGriff23-Sep-18 21:38 
GeneralRe: How to get last day of specific date Pin
Maciej Los23-Sep-18 22:02
mveMaciej Los23-Sep-18 22:02 
GeneralRe: How to get last day of specific date Pin
OriginalGriff23-Sep-18 22:26
mveOriginalGriff23-Sep-18 22:26 
AnswerRe: How to get last day of specific date Pin
OriginalGriff23-Sep-18 21:38
mveOriginalGriff23-Sep-18 21:38 
AnswerRe: How to get last day of specific date Pin
Richard MacCutchan23-Sep-18 21:54
mveRichard MacCutchan23-Sep-18 21:54 
QuestionStackoverflow Pin
Thomas Kiær23-Sep-18 0:28
Thomas Kiær23-Sep-18 0:28 
AnswerRe: Stackoverflow Pin
OriginalGriff23-Sep-18 1:13
mveOriginalGriff23-Sep-18 1:13 
GeneralRe: Stackoverflow Pin
Thomas Kiær23-Sep-18 5:45
Thomas Kiær23-Sep-18 5:45 
GeneralRe: Stackoverflow Pin
OriginalGriff23-Sep-18 6:04
mveOriginalGriff23-Sep-18 6:04 
GeneralRe: Stackoverflow Pin
Thomas Kiær23-Sep-18 6:14
Thomas Kiær23-Sep-18 6:14 
GeneralRe: Stackoverflow Pin
OriginalGriff23-Sep-18 6:27
mveOriginalGriff23-Sep-18 6:27 
QuestionC# Post files through rest api error Pin
Pradeep Kumar21-Sep-18 13:07
Pradeep Kumar21-Sep-18 13:07 
AnswerRe: C# Post files through rest api error Pin
Richard MacCutchan21-Sep-18 21:37
mveRichard MacCutchan21-Sep-18 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.