|
Are there any problems remaining after the cast to List<object> is replaced with List<Person> ?
Alan.
EDIT hope that ok now, was having a problem with the angle brackets around Person but not object!!
|
|
|
|
|
List<Person> works fine, List<object> does not.
I get: Unable to cast object of type 'System.Collections.Generic.List`1[WindowsFormsApplication1.Person]' to type 'System.Collections.Generic.List`1[System.Object]' in both last lines on the main proc.
i want it to work for other classes then Person also.So, BindData<person>(list) or BindData<car>(list), based on the name of the list property in class Data ("Persons" or "Cars").
modified 29-Jun-14 5:49am.
|
|
|
|
|
The Combobox.DataSource property is typed as Object and so you can infer that the Combobox must be checking the compatibility of the assigned data source. The only requirement is that the data source implements the non generic IList interface. You could cast to that but the combox box will accept the data source directly without casting.
Alan.
|
|
|
|
|
you're right! it works. thanks! i was thinking too complex i guess.
|
|
|
|
|
joost.versteegen wrote: give me a hint
Avoid Reflection.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Even without using reflection, you won't be able to cast a List<Person> to a List<object> , because that would let you break the list.
Consider what would happen if this cast was allowed:
List<Person> onlyContainsPeople = new List<Person>();
List<object> containsAnyObject = (List<object>)onlyContainsPeople;
containsAnyObject.Add(new Hippopotamus());
Person thePerson = onlyContainsnPeople[0];
You now have a list which is guaranteed to only contain Person objects, but the only object in the list is not a Person object. Either the line which adds the item to the list would have to throw an exception, or the line which retrieves the item from the list would have to throw an exception. Neither exception would be obvious or expected.
There are a few generic interfaces and delegates which, in .NET 4.0 or higher, are declared as covariant or contravariant, which will allow something similar to what you're trying to do:
List<Person> onlyContainsPeople = new List<Person>();
IEnumerable<object> containsAnyObject = onlyContainsPeople;
Generic covariance only works for read-only interfaces/delegates - the generic type parameter is only ever returned, never passed in. Contravariance only works when the type parameter is only ever passed in, never returned.
See Covariance and Contravariance in Generics[^] on MSDN for more information.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi everyone! btw I'm jomilyn and i'm new here.... we will going to make our thesis project this time and i just want to ask some help with regards in using biometrics in c# maybe some of you have experience on how to code biometrics in c# especially in using fingerprint to register... please let me know if you have some idea... thanks!
|
|
|
|
|
You need a fingerprint scanner and an API. Any other questions?
|
|
|
|
|
in our case we use digital persona and install sdk... But i don't know how to connect it with c#
|
|
|
|
|
So, talk to the manufacturers - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Ok dear... thanks for the suggestion...
|
|
|
|
|
BTW: I know it's an Indian "thing", but don't use "dear" online.
In the west it's seen as condescending and patronising if the person you direct it at is female: and on the internet you have no idea what gender anyone is.
Not a problem to me, but it's best to avoid it.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Yes Dear.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
The type or namespace name 'Emailhandler' could not be found (are you missing a using directive or an assembly reference?)
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Emailhandler;<-- the problem
thanks
|
|
|
|
|
Well, there is no standard .NET class "Emailhandler" so you need to look at where you got it from, and ensure that the assembly is referenced if necessary.
Also be aware that namespaces are case sensitive, so if it should be EmailHandler instead, then:
using Emailhandler; Won't find it, but
using EmailHandler; would.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
where I can it and how to assembly referenced it EmailHandler include in c#
|
|
|
|
|
Sorry? Would you mind trying English sentences as well as words?
I don't understand that at all!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
sorry for my language , where I'am could the EmailHandler and how to install in c# 2008, thanks before
|
|
|
|
|
That's OK - it'll just take longer since we don;t fully understand each other!
I don't know of an EmailHandler class or namespace - so either you got it from somewhere, or wrote it yourself, or you need a class to handle something to do with Emails.
If you got it from somewhere, then it probably came in it's own assembly and you need to add a reference to that assembly: open your project, and right click "References", the select "Add Reference" - the dialogs should help you find the file - then click "Add" and "Close".
If you wrote it yourself then it will be a project, possibly in the same solution. Let me know how you created it and I'll try and help you through. (There are a lot of different ways you might have written it)
If you are trying to find something - anything - that can work with emails, then I need more information on what you want to do: receive or transmit for example, plus any details you can give me.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
thanks, actually this is a create new class and follow the namespace to the main class name must to be same.
next question is: 'EmailHandler.Properties.Settings' does not contain a definition for 'SMTPAddress' and no extension method 'SMTPAddress' accepting a first argument of type 'EmailHandler.Properties.Settings' could be found (are you missing a using directive or an assembly reference?)
whether should configuration in IIS to create into SMTPAddress server?
|
|
|
|
|
Sorry, but I think you need to find a site in your own language - what you are saying doesn't make a lot of sense in English, or you are very, very confused about how to write a class. You can't just create a class called "EmailHandler" and expect it to automatically know how to deal with emails!
Have a look at this: Sending an Email in C# with or without attachments: generic routine.[^] It's the method I use to send an eamil, and it may give you some pointers on what you are trying to achieve.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
In C#, suppose there are two forms: frmMain and frmChangePass, frmMain open before then click Open to frmChangePass, ask frmChangePass are not allowed to move or not to allow select frmMain, must have entered the frmChangePass and play again for the allowed select frmMain.
|
|
|
|
|
I'm not sure exactly what you are trying to do, but I'm guessing that you are trying to show a "enter password" form and that the main form cannot be allowed to respond or be selected until the user has successfully entered the correct value.
If so, then that's simple. In your main form:
frmChangePass fcp = new frmChangePass();
if (fcp.ShowDialog() == DialogResult.OK)
{
...
} The method will wait for the new form to close before continuing.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Your writing style form frmChagePass has moved. I don't want move form frmChagePass or select form other when form frmChagePass not close. Do you understand ?. Note: i using net 2.0
|
|
|
|
|
Not sure I do...Are you trying to prevent a form from moving at all? And prevent the user accessing any other application?
If not, please try to explain in your native language, and then translate that via Google - that might make it easier!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|