Good afternoon,
Can someone please tell me if I can set default parameter values when using lambda expressions in C#? For example, if I have the code
public static Func<String, Int32, IEnumerable<String>> SomeFunction = (StrTmp, IntTmp) => { ... },
how can I set IntTmp's default value to, for example, two? The usual way to set defaul...
Please help this Linq newbie!
I'm creating a list inside my class under test, and I would like to use Moq to check the results.
I can easily put together a Predicate which checks the results of the list. How do I then make that Predicate into an Expression?
var myList = new List<int> {1, 2, 3};
Predicate<List<int>> myPredicate = (lis...
How do I compare two lambda functions in C++ (Visual Studio 2010)?
std::function<void ()> lambda1 = []() {};
std::function<void ()> lambda2 = []() {};
bool eq1 = (lambda1 == lambda1);
bool eq2 = (lambda1 != lambda2);
I get a compilation error claiming that operator == is inaccessible.
EDIT: I'm trying to compare the function instance...
I am using Enterprise Library.I want to map the column (of integer type) to Enum Type.
Say
Enum BloodGroup Type
{
OPositive,
ONegative,
ABPositive,
ABNegative,
BPositive,
BNegative,
NotSet
}
I am mapping Database Table's column to C# Types's (Class Employee) Properties.
IRowMapper<Employee> addressMapp...
I'd like to say
int x = magic(), y = moremagic();
return i => i + (x/y);
and have the x be captured as a constant instead of a variable reference. The idea is that x will never change and so when the expression is later compiled, the compiler to can do constant folding and produce more efficient code -- i.e. calculating x/y once inst...
I Have a few lines of code
public void CreateMethod<TContract>(Expression<Action<TContract>> method)
{
var innerMethod = Builder.DefineMethod("SomeName",MethodAttributes.Private);
method.CompileToMethod(innerMethod);
//more code
}
However the second line fails. I've tried with different versions of DefineMethod with little lu...
I'm trying to use a method group in a lambda expression, like this:
public class Foo { public void Hello(string s) { } }
void Test()
{
// this works as long as Hello has a void return type
Func<Foo, Action<string>> a = foo => foo.Hello;
}
When I change the return type of Hello to int, however, I get
'Bar.Hello(string)' ha...
How can I change if (propType.PropertyType == typeof(string)) and if (propType.PropertyType == typeof(int)) to something more dynamic?
private void button2_Click(object sender, EventArgs e)
{
var lista = _pessoas.AsQueryable();
if (textBox2.Text != "")
{
var param = Expression...
We have an object and we want to build a linq query based on that object on the fly. This linq statement is equivalent to what we want to build:
Expression<Func<Sample, bool>> linqExpression
= x => x.Child == itemToCompare.Child;
We can't quite come up with the right expression to build the itemToCompare.Child part. Here'...
I'm having a Dictionary like
Dictionary<String, List<String>> MyDict = new Dictionary<string, List<string>>
{
{"One",new List<String>{"A","B","C"}},{"Two",new List<String>{"A","C","D"}}
};
I need to get a List<String> from this dictionary, The List should contain Distinct items from the values of the above ...
The list view is like
i need to add the data from the Listview to a Dictionary<String,String>.
Now i'm using for loop to do this. Is there any way to do this using LINQ.
Finally the Dictionary will contain
{"A","1"}
{"B","2"}
{"C","3"}
EDIT My code :
Dictionary<String, String> Dic = new Dictionary<string, string>();
...
The First Dictionary is like
Dictionary<String, String> ParentDict = new Dictionary<String, String>();
ParentDict.Add("A_1", "1");
ParentDict.Add("A_2", "2");
ParentDict.Add("B_1", "3");
ParentDict.Add("B_2", "4");
ParentDict.Add("C_1", "5");
i need to convert this into a new Dictionary...
I use Entity Framework 4.
How can I perform a Generic Where Lambda Clause.?
I Have many Entity that need the same Where Query.
public Func<SupplierTypeText, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
public Func<ProductText, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
public Func<CategoryText, bool> GetLmbL...
I've seen two recent answers using _1 as a pure C++0x solution (no explicit mention of boost lambdas).
Is there such an animal as std::_1 I would think that having native lambdas will make such a construct redundant.
A Google code search for std::_1 brings two results from the same project so that's inconclusive.
...
Hi,
I'm trying to write an in-line function for count occurrences of a word in a string using lambda expressions recursively.
The function:
Func<string, string, int> getOccurrences = null;
getOccurrences = (text, searchTerm) =>
text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) == -1
? 0
: getOccurrences(
text.Su...
I have a list of items and wish to set one of their properties to a certain value:
applist.ForEach(Function(x) x.PrePaidTypeID = CInt(DBEnums.PrePaidType.NoPrepay))
...but we think this just does a boolean comparison. Is there a way to force VB to assign the integer value rather than compare it?
...
Hello,
I have the following code:
btnTest.Click += (sender,e) => SomeAction()
why does this code works in WinForms and not in asp.net. In asp.net I had to do the following:
btnTest.Click += new EventHandler(SomeAction);
target framework in both cases is .net 4.0
...
I am trying to run a query where I get the name of locations and the number of items in that location. So if i have a program that contains 3 locations I want to know how many programs are in that location..I need to use this with a lambda expression or linq to entities.
return Repository.Find(x => x.Location.Name.Count())...clearly mis...
I Have 3 entities.
Product
LangID
ProductName
Category
LangID
CatName
ProductType
LangID
TypeName
As you can see, each of them has LangID Property.
I Would like be able to create a generic repository that will contain only one function that will return an Func<T, bool> GetLmbLang()
public interface IBaseRepository<T> where T : c...
Initialization of list with lambdas causes high IL cyclomatic complexity: why, and how remove this complexity?
For example following code causes the static constructor of the class (which is actually compiler generated) to be very complex: 1 + the list count.
static List<Predicate<string>> list = new List<Predicate<string>>()
{
s =>...