Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Was going through this code here
The code here confused me
private void sendMessage()
{
IConnectionFactory wlsConnectionFactory;
IQueue ordersQueue;
IDictionary<string, Object> environment;
IContext jndiContext;
In dot net and C# a I prefix means a Interface no ?
If the above statement is true what does this line mean for example
IQueue ordersQueue;
Would this program have worked if we had something like
Queue ordersQueue instead of IQueue ordersQueue ?
First of all, an I prefix implies an interface, but that's just a convention (albeit, a extreme widely-used convention)
IQueue ordersQueue;
means that ordersQueue can be assign any type which implements the IQueue interface.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is it possible to add some data, such as 123, to the "intList" variable below?
IQueryable<int> intList = Enumerable.Empty<int>().AsQueryable();
Many thanks in advance.
I would suggest one of the following options:
Either (if intList already exists):
intList = intList.AsEnumerable().Append(123).AsQueryable();
Or if it doesn't:
var intList = new List<int>(1){123}.AsQueryable();
Note generally AsQueryable is not commonly useful - but in contexts like unit tests (which seems to be your scenario here), code like above is acceptable.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
class Class1<T>
{
T Value;
void Method1()
{
if(Value is int)
Value = 42;//CS0029
}
}
Is there any way to make code like this work?
It is possible, but usually there is something wrong with the code if you need to do this in a generic class.
if (Value is int)
Value = (T)(object)42;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm having elementary problem with trying to query System.Windows.WindowCollection at some point in my code i have
WindowCollection z = Application.Current.Windows;
and would like to do z.Any();
The definition of WindowCollection Class is as follows
public sealed class WindowCollection : ICollection, IEnumerable
As you may see, it doesn't implement IEnumerable<Window>, so in order to have access to the most of the Enumerable extension methods, you need first to use Enumerable.Cast like this
z.Cast<Window>().Any();
LINQ works only with IEnumerable<T> interface. WindowCollection impliments only IEnumerable. There two options:
Cast<T>() - this return IEnumerable but if collection has element which can't be casted to T exception will thrown.
OfType<T>() - this returns IEnumerable. It skips element which can't be casted to T, that is why I prefer OfType.
Application.Current.Windows.OfType<Window>().Any();
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a problem with a class that is to spawn instances containing one out of about 30 objects of different types (I call it out_out_of_many_types_of_subcontract in the code snippet below).
class supercontract
{
void supercontract (float date, one_out_of_many_types_of_subcontract subcontract)
{
stuff....
}
}
Is there any way of declaring a semi-generic variable or must I (1) resort to polymorphism between constructors or (2) casting an object as a certain type with a block of (else)if clauses?
Cheers!
I would make them all implement a single interface.
interface IContract{}
class AContract: IContract {...}
Even if the interface is empty you can limit what types could be passed to your method.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am currently trying to implement a marker interface in c#. But I haven't done this so far so I'd like to ask you for advice please.
Short my problem:
I've a interface Factory, and the factory contains several subinterface which should be marker interface because they don't have a property or method or something. So the marker interface should implement the interface factory. And my marker interface is for example for Cars, Trucks etc. And the marker interface is implemented for Cars for MyBMW, MyAUDI etc. How can I implement such a pattern? Thanks!
interface Factory
{
string[] process (string [] entry);
}
You should think about using Attributes instead of interface to mark classes.
then you can decide in your code how to handle specific instances as the attribute is set.
I believe you want to implent the factory pattern. I suggest you to look an example here:
http://en.wikipedia.org/wiki/Factory_method_pattern