Reputation: 1944
I'm afraid I'm a little new to C#, so I simply copied some code from his documentation. This is using the MailChimp Amazon Simple Email Service API
var api = new SesApi(yourMailChimpKey);
var result = api.SendEmail("Subject for test email",
"<p>Body of HTML email</p>",
"Body of plain text email",
new EmailAddress("Sender name", "[email protected]"),
new List { new EmailAddress("Recipient", "[email protected]") },
tags: new List { "test" } //Problems are on this line, and the one above it
);
The problem is that visual studio (I'm using .net 4.5) doesn't seem to be able to resolve the sections where is says "new List {...}"
Am I missing a library, or is there a newer way to do this that I've missed?
Upvotes: 1
Views: 681
Reputation: 244777
The problem is that there is no type List
. There is only the generic List<T>
, which is most likely what the documentation meant to use. (The non-generic version is ArrayList
, but you really shouldn't use that.)
This means you need to specify the type of the list in your code:
new List<EmailAddress> { new EmailAddress(…) }
new List<string> { "test" }
(This assumes you have using System.Collections.Generic;
at the top of your code file.)
Assuming the API accepts any collection, simpler solution might be to use an array:
new[] { new EmailAddress(…) }
new[] { "test" }
Upvotes: 2
Reputation: 2008
I think you've got a couple of issues.
First, you need a using System.Collections.Generic;
directive at the top of your file, as noted by Moshe.
Then, try putting parentheses after your list declaration, like this example:
private void Form1_Load( object sender, EventArgs e )
{
ListParam( new List<string>() { "Item 1", "Item 2" } );
}
private void ListParam( List<string> mylist )
{
MessageBox.Show( "List count = " + mylist.Count );
}
Upvotes: 0
Reputation: 2668
Notice there's a difference between "using System.Collections" to "using System.Collections.Generics". The later requires that you specify the list type, such as "new List<EmailAddress> { new EmailAddress ... }
"
Upvotes: 1