|
yes.. Add them to new list ..
|
|
|
|
|
Adding lists is a simple matter (see here[^]), what is your difficulty?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Use the List<T>.AddRange function - it will add all the elements of any IEmumerable to a List<T>
List<string> l1 = new List<string>();
...
List<string> l2 = new List<string>();
...
l2.AddRange(l1)
;
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi OriginalGriff,
I dont want to append list. i want sum
Regards
Saurabh
|
|
|
|
|
I suggest you repost this here, or on C# QA, with a code example clearly showing the structure of the Lists, and clearly showing exactly what the final result's structure (another List ?) should be, and telling us, clearly, how the final result is composed from the outermost Classes, using the innermost Classes, and their inner Properties (of Type: List of doubles).
From what you've disclosed here, we can only make "wild guesses" at the underlying structure like:
public class CD
{
public CD(?) {?}
public class CDA
{
public CDA(?) {?}
public List<double> cda1 {get; set;}
public List<double> cda2 {get; set;}
}
public class CDB {}
public class CDC {}
}
public List1<CD> list1 = new List<CD>();
public List2<CD> list2 = new List<CD>();
public List3<CD> list3 = new List<CD>();
public List<CD> SumOfLists = You need to clarify exactly what you mean by "nested." And, is inheritance used in any way here ?
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
hello guys... I have got this email program from internet, which works absolutely fine. But I wanna catch exceptions when something goes wrong, and I dont know what to catch. Here is the program
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("username@gmail.com", "password");
MailMessage msg;
MailAddress from;
MailAddress to;
from = new MailAddress("From Email Address", "my name here", System.Text.Encoding.UTF8);
to = new MailAddress("To Email Address");
msg = new MailMessage(from, to);
msg.Body = txtBody.Text;
msg.Body += Environment.NewLine;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.Subject = txtSubject.Text;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
client.Send(msg);
msg.Dispose();
thnx for any suggestions.
|
|
|
|
|
You should at least catch an SmptException , which will be thrown if for any reason the email was unable to be sent. You can use the SmtpStatusCode enum to find out the reason, something like this:_
try
{
client.Send(message);
}
catch (SmtpException ex)
{
MessageBox.Show(String.Format("Error: {0}", ex.StatusCode));
}
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Here is what I do.
string RetMsg = string.Empty;
try
{
client.Send(message);
RetMsg = "Success";
}
catch (SmtpException ex)
{
RetMsg = String.Format("Error: {0}", ex.StatusCode);
}
MessageBox.Show(RetMsg);
Now I receiver's email address something like: "address@yaho.com". You see there is problem with the mail address? But it still shows me Success. What's wrong?
|
|
|
|
|
There is nothing wrong with that email address; there may well be a domain out there called yaho.com. However, if that domain does not exist the SMTP system will send you a message telling you that the email is undeliverable; but that will not cause an exception in your code.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
SmtpClient has no conception of correct email addresses. It will send the message to any address you type in, regardless of whether it is a correct address or not. You will only get notification that the sending failed from your smtp server. If you want to send messages to correct email addresses, you will need to construct your own validation routine, using something like regular expressions or a list of known(authorised) addresses, and pass all messages through that first before sending.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
that's not good enough. You should use sendasync coupled with a completeCallback.
Then you should have the error/delivery failure. That depends on the SMTP Mail server itself that you are using. See here
All the best,
Dan
|
|
|
|
|
I have 3 classes:
[Serializable]
public class _ModelBase
{
public Guid Id { get; set; }
public string Caption { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
public int Sequence { get; set; }
public ImageSource Image { get; set; }
}
and
[Serializable]
public class FolderModel : _ModelBase
{
public List<FolderModel> Folders { get; set; }
public List<FileModel> Files { get; set; }
public bool IsExpanded { get; set; }
public FolderModel()
{
Folders = new List<FolderModel>();
Files = new List<FileModel>();
}
}
and
[Serializable]
public class FileModel : _ModelBase
{
public string FileName { get; set; }
}
I'm trying to serialize a a collection of FolderModels and FileModels:
private void saveAppDataToFile()
{
using (TextWriter textWriter = new StreamWriter(xmlDataFile))
{
XmlSerializer serializer = new XmlSerializer(typeof(FolderModel));
serializer.Serialize(textWriter, Folders);
textWriter.Close();
}
}
I'm gettng the runtime error
"There was an error generating the XML document."
"Unable to cast object of type 'System.Collections.Generic.List`1[MyApp.Models.FolderModel]' to type 'MyApp.Models.FolderModel'"}
I can't figure out why this won't work. Anyone see what's wrong?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: a collection of FolderModels and FileModels I think it would be useful to see the structure/definition of that Collection.
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
I think there is an issue around the xml serialising of complex object, your List<>s make this a complex object. There are literally dozens of alternative serialisers and many articles written on the subject.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah just like Microft Mycroft Holmes said. It doesn't let you serialize a collection.
Instead use a foreach and serialize each folder indivitually.
Something like:
using (TextWriter textWriter = new StreamWriter(xmlDataFile))
{
XmlSerializer serializer = new XmlSerializer(typeof(FolderModel));
foreach(folder in Folders) serializer.Serialize(textWriter, folder);
textWriter.Close();
}
All the best,
Dan
|
|
|
|
|
This is a fairly simple one to fix and the error is actually pretty helpful. You told the serializer that you were going to serialize FolderModel but you then try to serialize a list of FolderModel instead.
|
|
|
|
|
SLAP!
That's the sound of me slapping myself.
Thanks!
Everything makes sense in someone's mind
|
|
|
|
|
Hey, no problem. If I hadn't made a similar mistake several thousand times, I'd probably have missed it.
|
|
|
|
|
I find this code a challenge to understand because it appears to me there's a circular (recursive) reference inherent in the structure of the FolderModel class.
Assuming there's no recursion inherent in the data structure itself: all he has to do is to call:
serializer.Serialize(textWriter, FolderModel1); And that's it ?
Your brilliance is shining through again
thanks, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
Hi all,
I got some user filled PDF forms, from there i need to extract the user filled data.Is there any possible way using C# other than 3rd party tool?
Thanks in advance
|
|
|
|
|
No, there is no native support for PDF files built-in to .NET. You'll need to use one of the many 3rd party libraries.
No comment
|
|
|
|
|
|
Thanks for your reply, but i need to fetch the user filled fields.
Is there any way to fetch those field values/tables?
|
|
|
|
|
Hi,
I am hosting an ActivX control in C#. The control has a method as follows...
GetMinMaxVals(bouble* pdMinX, double* pdMaxX, double* pdMinY, double* pdMaxY);
The caller may pass null (zero) for any of the parameters that are not required. I only need a value for pdMaxX.
Question is: How do I pass null for the arguments i do not require?
Thanks - John.
|
|
|
|
|
I don't see a problem. What does your code look like? What have you tried? How does it fail?
|
|
|
|