|
|
With the default approach, you would only be able to do this if T implements IComparable . Suppose that you have the following class:
public class Cmp
{
public string Name { get; set; }
} With the default List.Sort(); , you would need to ensure that the class looks something like this instead:
public class Cmp : IComparable<Cmp>
{
public string Name { get; set; }
public int CompareTo(Cmp obj)
{
if (Name == null) return -1;
return Name.CompareTo(obj.Name);
}
} Now, suppose that you cannot modify the underlying library? Well, Sort accepts classes that derive from Comparison , or that implement IComparer<T> so you can create a new comparer that might look something like this:
public class CustomCmpComparer : IComparer<Cmp>
{
public int Compare(Cmp x, Cmp y)
{
if (x.Name == null) return -1;
return x.Name.CompareTo(y.Name);
}
} Then, your Sort call would look something like this instead:
myList.Sort(new CustomCmpComparer());
|
|
|
|
|
Generics are functions that work regardless of the type they are bound to. If you need to call a method then your function is no longer generic as it can't be used with any type. In order to do this your types will need to implement an interface that has your method on it
public interface IMyInterface
{
bool Compare(object target);
}
public class MyClass : IMyInterface
{
public bool Compare(object target)
{
return true;
}
}
When defining your generic function you can now stipulate that the type used has to implement your interface
private void MyFunction<T>(T data, T data2) where T : IMyInterface
{
data.Compare(data2);
}
You can now call your generic method but it must be bound to an object that implements your interface, it is no longer 100% generic.
MyFunction<MyClass>(new MyClass(), new MyClass());
MyFunction<SqlConnection>(new SqlConnection(), new SqlConnection());
|
|
|
|
|
The zero parameter Sort method on List<T> expects that T implements IComparable<T> or IComparable interface. If it does not an InvalidOperationException will be thrown. If T does implement the interface then knowing this List<T> can cast T to IComparable<T> or IComparable and call the Compare method. No need for reflection and List<T>>otherwise doesn't understand much about T at all, other than that it either does or does not implement IComparable<T> or IComparable.
If you want your "generic" to be able to call a method on T that is not exposed via a known interface or subclass you will probably need to resort to reflection or use some other way of mapping to the target method. While List<t> does not do this, you can constrain the type parameter for your generic such that it must implement certain interfaces or derive from a certain class allowing your generic class to call the methods known to be exposed via the super class or interfaces.
|
|
|
|
|
If you define List<T> where T: Icomparable , I think the compiler will object if it doesn't.
|
|
|
|
|
User register from windows form application and then insert that data to webserver database please help me.
|
|
|
|
|
That is not a question, that is functionality. As is, the task is a bit large to explain.
Have you inserted data into a database before? If not, that is where you start.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I need to display some summary details in the RDLC report and also i need that in the form of table. I tried vertical tablix and bond values with DataSet but right now my problem is the summary details are showing vertically twice.
Eg. I need
Sum1 val1
Sum2 val2
Sum3 val3
Total val1+val2+val3
BUT right now its displaying like
Sum1 val1
Sum2 val2
Sum3 val3
Total val1+val2+val3
Sum1 val1
Sum2 val2
Sum3 val3
Total val1+val2+val3
|
|
|
|
|
That is the code? I am sure not, so the code of your application would help us understand the context and problem.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thanks..
|
|
|
|
|
I would like to know if it is possible to develop an webcam application under WPF C# to capture webcam image and save it to disk without showing the preview (showing the content to the user)?
|
|
|
|
|
|
|
Great! Please help me with a few codes in WPF C# so I could implement this to my application.
Please note that the objective is not to aware the user of the webcam activity at all.
Thanks in advance.
|
|
|
|
|
I said it's possible, I did not say I know how to do it. You need to study the webcam interface to see what you need to do in order to capture the activity without displaying it. But personally I would never install such an application on my PC.
|
|
|
|
|
Let me clear my objectives one more time before it creates any ambiguity.
This is an application where the user puts a few input in a sequence of pages. Every time the user enters into a page the application captures the image of his/her face along with the other activities with 2 webcams. Reason to take the image is to resolve any dispute if occurs. It would be awkward to show the webcam preview on the input pages. If we had to put an image control it has to be on the main window keeping it hidden.
This is a DropBox application to be written in C# WPF where there are 2 webcams - 1 for the user face and the other at the DropBox shutter end to capture if the user actually dropped anything.
|
|
|
|
|
And how are you going to switch off the Webcam notification itself? You know, the light that appears on the camera when it's in use.
|
|
|
|
|
Since all the webcams are inside the cage the light can not be seen by the user.
|
|
|
|
|
Do take note that this might not be legal in some places
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Don't worry, the DropBoxes are generally like this and it does not have any illegal elements. And by the way we are actually looking for something where there is no preview - just capture on demand. So, even if the user sees the light of the webcam it really doesn't matter because it actually strengthens his side in case of any dispute unless he claims anything useless (like claiming transaction without dropping the envelop).
|
|
|
|
|
Eddy didn't mean illegal activity, but more of the legality of having a person on camera. You may need to have consent from the person or some notification that they are being filmed.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
Ultimately the webcam image is just a stream of bytes. That's all you need to know to work out the rest.
|
|
|
|
|
Yes. But how do I do it without showing it on the image control?
|
|
|
|
|
It's a stream of bytes. The image control just renders the bytes out - it's a convenience for you. You don't need it. Think about how you save a stream of bytes instead - that's the key. Forget that the Image Control ever existed.
|
|
|
|
|
This is where I failed to implement. Can you please share with me a few codes so I could understand the fact to store the stream anything other than the image control and grab the current from that variable?
|
|
|
|