Does anyone know a good (free) C# eBook for Intermediate programmers? I want something that covers generics, threads, events, delegates, etc.
See also: http://stackoverflow.com/questions/391523/what-are-some-good-free-programming-books#392926
...
What's the explanation for the following:
public class GenericsTest {
//statement 1
public ArrayList<Integer>[] lists;
public GenericsTest()
{
//statement 2
lists = new ArrayList<Integer>[4];
}
}
The compiler accepts statement 1. Statement 2 is flagged by the compiler for "generic array creation"....
I seem to be using the wrong search terms for this in Google...
I have written a Generic Class for Many-To-Many Associations, but I'm guessing this has already been done. It is highly likely that it exists in an implementation much better than my own. This is my first foray into writing a generic class.
For a better idea of what I'm ...
I have a generic class
public MyClass<TContext, T> where TContext : DataContext
that effectively acts on an instance of another
public class MyOtherClass<T> : IEnumerable<T>
I want to enforce that the TContext has a Table<T>. Is there a clean way to enforce this?
...
Is there a way to initialize all elements of an array to a constant value through generics?
...
can ASP.NET controls be used with generics? Never seen this done and want a way to differentiate some controls on a page by type, ie: DateTime vs int
example:
public class MyGenericTextBox<T>: TextBox
{
public MyGenericTextBox<T>() {... }
}
...
I have the following class in my C# .NET 3.5 win forms app:
class Field {
string objectName;
string objectType;
string fieldName;
string fieldValue;
}
and a List fieldList that is a datasource for a checkedlistbox. This listbox shows all the distinct objectNames from my fieldList collection.
I want to create another checkedlistbo...
I'm currently working on a wcf service that does some lookups in a database and return the data to the client. The user has entered an id of something he wants to see in a textbox. This could be a client-id, a product-id, an order-id or whatever. The lookup method on the server tries to find the id in the client table. If it's not in the...
Are any of the .NET generic collections marked as IXmlSerializable? I've tried List<T> and Collection<T> but neither work out of the box.
Before I roll my own collection<T>, list<T>, or dictionary<T> class, I thought I'd check to see whether Microsoft had included something that does this already. It seems like basic functionality.
EDI...
Hi,
I know that C# supports covariance in arrays like this :
object[] array = new string[3];
But I'm getting an error when it tries to compile the below code
class Dummy<K,T> where T:K
{
public void foo()
{
K[] arr = new T[4];
}
}
It says "Cannot implicitly convert type 'T[]' to 'K[]' "
Why I'm getting this er...
I've got a custom object (example only code for ease of understanding) ...
public class MyClass
{
private string name;
private int increment;
private Guid id;
public string Name
{
get { return name; }
set { name = value; }
}
public int Increment
{
get { return increment; }
...
I have two List's which I want to check for corresponding numbers.
for example
List<int> a = new List<int>(){1, 2, 3, 4, 5};
List<int> b = new List<int>() {0, 4, 8, 12};
Should give the result 4.
Is there an easy way to do this without too much looping through the lists?
I'm on 3.0 for the project where I need this so no Linq.
...
Is there a way to convert a list(of object) to a list(of string) in c# or vb.net without iterating through all the items? (Behind the scenes iteration is fine - I just want concise code)
Update:
The best way is probably just to do a new select
myList.Select(function(i) i.ToString())
or
myList.Select(i => i.ToString());
...
I have BaseAbstractClass(of T as WebControl) (VB Generics) which inherits WebControl.
BaseAbstractClass is inherited by ConcreteWrapper1, ConcreteWrapper2, and lastly, to shake things up a bit, ConcreteWrapper4. Each of these would inherit BaseAbstractClass using a different class inherited from WebControl.
What I would like to do is...
I have a List of a "complex" type - an object with a few string properties. The List itself is a property of another object and contains objects of a variety of types, as shown in this abbreviated class structure:
Customer {
public List<Characteristic> Characteristics;
.
.
.
}
Characteristic {
public string Characterist...
I have this class.
public class Foo
{
public Guid Id { get; set; }
public override bool Equals(object obj)
{
Foo otherObj = obj as Foo;
return otherObj == null && otherObj.Id == this.Id;
}
public override int GetHashCode()
{
return this.Id.GetHashCode();
}
}
You can see I overro...
In the sample code, the line with the 'error comment' gives the following the error -
Operator '<' is not defined for types 'T' and 'T'.
Why wouldn't VB automatically call the appropriate T operator? (i.e. If T is an integer then call the integer comparison functions.)
Is it possible to make this work in an elegant fashion?
This i...
Most references I've seen, and my IDE's code completion all have my specifying a Generic type on both a variables type and its implementation eg.
List<String> string = new ArrayList<String>();
Recently I've started skipping the generic type on the implementation eg.
List<String> strings = new ArrayList();
assuming that the compiler...
namespace GenericsTest
{
public class AGenericClass<T>
{
public class NestedNonGenericClass
{
}
}
}
In the example above, should NestedNonGenericClass be considered a generic class?
The reflection API says it's a generic class, and even hands me the template parameters of the containing class as the...
Given the following generic interface and implementing class:
public interface IRepository<T> {
// U has to be of type T of a subtype of T
IQueryable<U> Find<U>() where U : T;
}
public class PersonRepository : IRepository<Employee> {
}
How could I call the Find method without specififying U?
var repository = new EmployeeRe...