I have created a custom ASP.NET control ( derived from WebControls.TextBox).
I want to add a property to that control which will be of a type.
This property will actually always be some type of enum .
So when in the designer I look at the properties window of that control - I want to be able to assign value to that property by a selec...
I've coded something like this:
public bool IsDataChanged()
{
T value1 = GetValue2;
T value2 = GetValue1();
return (valueInDB != valueFromView);
}
Right now the function doesn't compile with the error "Operator '!=' cannot be applied to operands of type 'T' and 'T'". What do I have to do to make this function w...
Can someone explained, as detailed as possible, the differences between the following types?
List
List<Object>
List<?>
Can I get an answer, not a link?
Let me make this more specific.
When would I want to use
public void CanYouGiveMeAnAnswer( List l ){}
?
When would I want to use
public void CanYouGiveMeAnAnswer( List<Object...
I have to be missing something obvious here. I don't get why this cast of the results of a linq query returns null and not the typed list I'm requesting.
IList<IMyDataInterface> list = query.ToList() as IList<IMyDataInterface>;
The complete code to run this is below. This is a knowledge gap I need to bridge. I have tried all kinds of ...
Does anyone knows why you can't create a generic indexer in .NET
the following code throws a compiler error:
public T this<T>[string key]
{
get { /* Return generic type T. */ }
}
Does this mean you can't create a generic indexer for a generic member collection?
...
How can i add list in a generic class?
Firstly My generic Class is that:
[Serializable]
public class ScheduleSelectedItems
{
private string Frequency;
List FrequencyDays = new List();
private string Time;
private string StartTime;
private string EndTime;
private string StartDate;
...
I want to use a collection initializer for the next bit of code:
public Dictionary<int, string> GetNames()
{
Dictionary<int, string> names = new Dictionary<int, string>();
names.Add(1, "Adam");
names.Add(2, "Bart");
names.Add(3, "Charlie");
return names;
}
So typically it should be something like:
return new Dicti...
I had another developer ask why I use List all over the place ... and I thought about it for a minute ... and couldn't come up with a definitive answer.
If you inherit from the collection base class to extend instead of using List(Of T) - what advantages do you get? Or - what don't you get with List?
...
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication3Generics
{
class Program
{
static void Main(string[] args)
{
ScheduleSelectedItems sitems = new ScheduleSelectedItems("Yusuf");
ScheduleSelectedItemsList slist = new ScheduleSelectedItemsList()...
I have a DAL that makes calls to my Entity Framework Model. The calls return things like IOrderedQueryable and IQueryable objects. Should I convert them to something more universal in my DAL, such as List? But I assume that if I don't need to enumerate through the entire collection, this could be wasteful... So whats the best approac...
I have the following situation:
// A public interface of some kind
public interface IMyInterface {
int Something { get; set; }
}
// An internal class that implements the public interface.
// Despite the internal/public mismatch, this works.
internal class MyInternalConcrete : IMyInterface {
public int Somet...
These Codes really boring. And Tostring() give me error !!! Can you rearrange these codes ?
class Program
{
static void Main(string[] args)
{
string[] arraystr = { "yusuf", "mehmet" };
Ilist myitems = new Ilist(arraystr);
SelectedItemsList slist = new SelectedItemsList();
...
According to the Java Language Sepecification, 3rd edition:
It is a compile-time error if a generic class is a direct or indirect subclass of Throwable.
I wish to understand why this decision has been made. What's wrong with generic exceptions?
(As far as I know, generics are simply compile-time syntactic sugar, and they will be t...
public interface IProcessor<T>
{
void Process(T instance);
}
foreach(AbstractType instance in myClass.SomeCollection)
OnProcess(instance);
public void OnProcess<T>(T instance)
{
IProcessor<T> processor =
unityContainer.Resolve<IProcessor<T>>();
processor.Process(instance);
}
The problem with this code is that the in On...
Can someone explain to me why
@Override
public void fooMethod(Class<?> c)
doesn't override
public void fooMethod(Class c)
and gives me the following errors instead:
- Name clash: The method fooMethod(Class<?>)
of type SubClass has the same erasure as fooMethod(Class) of
type SuperClass but does not override it
- The method f...
Hello,
I have a question about Generics in Java, namely using wildcards. I have an example class GenClass like this:
public class GenClass<E> {
private E var;
public void setVar(E x) {
var = x;
}
public E getVar() {
return var;
}
}
I have another simple class:
public class ExampleClass {
}
I have ...
Okay so I have a scenario similar to the below code, I have a parent class that implements IComparable and a child class.
class Parent : IComparable<Parent>
class Child : Parent
Child a = new Child();
Child b = new Child();
a.CompareTo(b);
Now the above works fine, i can compare two of the child objects to each other no problem
L...
This question is self explanatory if you know how to use JMockit: How do I mock a method that has generics on it? I want to mock this method: public T save(T entity) but it always throws an exception like this:
mockit.RealMethodNotFoundForMockException: Corresponding real methods not found for the following mocks:
Object save(Object)
...
I really hate sometimes how IDictionary<TKey, TValue> [key] will throw an exception if the key doesn't exist in the dictionary.
Of course there is TryGetValue(), but that seems to have been optimized for performance and not usability.
So I thought, oh I'll just make an extension method for it - which I did :
public static class Collec...
Eclipse is giving me a warning of the following form:
Type safety: Unchecked cast from Object to HashMap<String, String>
This is from a call to an API that I have no control over which returns Object:
HashMap<String, String> getItems(javax.servlet.http.HttpSession session) {
HashMap<String, String> theHash = (HashMap<String, String...