Hi,
I'm using a distributed web application, with a database server housing the SQL Server 2005 database, an application server where we've installed a Microsoft Three Tier Service Application, and a web server where I using MVP with supervising controller.
My service layer, on the application server, returns an IEnumerable<Country> wh...
I have the following function to get validation errors for a card. My question relates to dealing with GetErrors. Both methods have the same return type IEnumerable<ErrorInfo>.
private static IEnumerable<ErrorInfo> GetErrors(Card card)
{
var errors = GetMoreErrors(card);
foreach (var e in errors)
yield return e;
/...
Possible Duplicate:
Upcasting and generic lists
Ok, I want to send a List<CardHolder> as an IEnumerable<ICardHolder> where CardHolder : ICardHolder. However, the compiler errors:
Error 4 Argument '1': cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'
This seems strange to me...
Suppose I have
var input = new int[] { 0, 1, 2, 3, 4, 5 };
How do I get them grouped into pairs?
var output = new int[][] { new int[] { 0, 1 }, new int[] { 2, 3 }, new int[] { 4, 5 } };
Preferably using LINQ
...
I wrote this:
public static class EnumerableExtensions
{
public static int IndexOf<T>(this IEnumerable<T> obj, T value)
{
return obj
.Select((a, i) => (a.Equals(value)) ? i : -1)
.Max();
}
public static int IndexOf<T>(this IEnumerable<T> obj, T value
, IEqualityComparer<T> comp...
I have the following code.
MyDataContext db = MyDataContext.Create();
bc =
db.BenefitCodes.Select(
b =>
new
{
BenCd = b.BenCd
, Description = b.BenDesc
, BenInter...
What is the impact on memory usage of using lots of iterators in C#? Let's assume a program that performs thousands of foreach loops -- does each loop allocate a temporary object on the heap via a call to GetEnumerator? Does the CLR perform any kind of optimization (e.g. stack allocation of IEnumerator objects)? Or is this simply not ...
I seem to be having an odd issue whereby every time I try to change a value of an item in a collection, it affects all others that contain the same initial values.
An example is below:
public class Product : ICloneable
{
public int Id { get; set; }
public string Name { get; set; }
public int Quantity { get; set; }
public Produ...
Is it possible to replace method ForEach() usage with Select() or something else to write next code in one string with nested extension methods? OR maybe there are another ways to improve the algorithm?
var list = new List<IStatementParser>();
System.IO.Directory.GetFiles(path, "*.dll")
.ForEach(f => System.Reflection.Assembly.Load...
Alright, hard to phrase an exact title for this question, but here goes... I have an abstract class called Block, that looks something like this:
public abstract class Block
{
public bool Enabled{get; private set;}
public virtual IEnumerable<KeyValuePair<string, string>> GetDefaultUsages()
{
yield return new KeyValuePair...
OK so here we go, one of my classes called Product is implemented like this:
namespace DomainModel.Entities
{
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
}
}
I want to a...
Please consider the following code:
public class Person
(
public string FirstName {get; set;}
public string LastName {get; set;}
Public int Age {get; set;}
}
IEnumerable <Person> people;
Also i have seen in many programs something like <IQueryable> what does that mean ?
What is the meaning of IEnumerable<Person> here ?...
Hi,
For log purpose, I would like to call the .ToString() method of every object on an object[] array. How can I do this in the simpliest way ?
Say I have :
myArray = new Object[]{"astring",1, Customer}
Log(????);
How can I pass un string such as its value is equals to "astring".ToString()+1.ToString()+Customer.ToString()
Or bette...
I have the following piece of code:
private Dictionary<object, object> items = new Dictionary<object, object>;
public IEnumerable<object> Keys
{
get
{
foreach (object key in items.Keys)
{
yield return key;
}
}
}
Is this thread-safe? If not do I have to put a lock around the loop or the y...
Hi,
I am working on some software that should be used for a special type of experiment.
The experiments are performed using:
1) A "Chip" (basically an XY grid of known dimensions).
2) Each Chip contains "Electrodes", identified by their X and Y coordinate on the chip and by a unique ID. Each electrode can also hold or not hold a sampl...
My question is concerning SQL connection status, load, etc. based on the following code:
public IEnumberable<MyType> GetMyTypeObjects()
{
string cmdTxt = "select * from MyObjectTable";
using(SqlConnection conn = new SqlConnection(connString))
{
using(SqlCommand cmd = new SqlCommand(cmdTxt, conn))
{
conn.Open();
...
I am having a hard time figuring out how to expose (& loop through) the properties
of my Categories class which was serialized (using JSON) in a WCF service and
deserialized on the server as illustrated below.
JavaScriptSerializer serializer = new JavaScriptSerializer();
Category cat = serializer.Deserialize<Category>(param1);
// M...
I keep getting errors trying to iterate through my ViewData in the view there... I even tried strongly typing the view to IEnumerable(App.Models.Namespace) and using Model, to no avail. Either I get an error for lack of a GetEnumerable method or invalid type casting... Any idea how I do this?
Model...
public IQueryable<Product> getAllP...
Finding myself in the situation where I have a method with this signature
void DoSomething(IEnumerable<T> before, IEnumerable<T> after)
I find myself often having to call it when I've just got one element and not IEnumerable.
I thought of adding the three overloads, but that doesn't help when one of the arguments is null.
So I thoug...
I am querying an HTML file with LINQ-to-XML. It looks something like this:
<html>
<body>
<div class="Players">
<div class="role">Goalies</div>
<div class="name">John Smith</div>
<div class="name">Shawn Xie</div>
<div class="role">Right Wings</div>
<div class="name">Jack Davis</div>
...