Search Results

Search found 220 results on 9 pages for 'enumerable'.

Page 6/9 | < Previous Page | 2 3 4 5 6 7 8 9  | Next Page >

  • Issue converting Sitecore Item[] using ToList<T>

    - by philba888
    Working with Sitecore and Linq extensions. I am trying to convert to from an item array to the list using the following piece of code: Item variationsFolder = masterDB.SelectSingleItem(VariationsFolderID.ToString()); List<Item> variationList = variationsFolder.GetChildren().ToList<Item>(); However I keep getting this error whenever I try to build: 'Sitecore.Collections.ChildList' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments I have the following usings: using System.Linq; using System.Xml.Linq; Am referencing: System.Core I've just copied this code from another location, so it should work fine, can only think that there is something simple (like a reference or something that I am missing).

    Read the article

  • Limited IList<> implementation ?

    - by Wam
    Hello people, I'm doing some work with stats, and want to refactor the following method : public static blah(float[] array) { //Do something over array, sum it for example. } However, instead of using float[] I'd like to be using some kind of indexed enumerable (to use dynamic loading from disk for very large arrays for example). I had created a simple interface, and wanted to use it. public interface IArray<T> : IEnumerable<T> { T this[int j] { get; set; } int Length { get; } } My problem is : float[] only inherits IList, not IArray, and AFAIK there's no way to change that. I'd like to ditch IArray and only use IList, but my classes would need to implement many methods like Add, RemoveAt although they are fixed size And then my question : how can float[] implement IList whereas it doesn't have these methods ? Any help is welcome. Cheers

    Read the article

  • .Net Array or IList<T> from NumPy array in IronPython?

    - by Barry Wark
    Imagine I have a .Net application that supports user extensions in the form of Python modules by embedding IronPython. Using Ironclad, I can allow users to make use of the NumPy and SciPy packages from within their modules. How good is the interop provided by Ironclad? My question is: can I use a NumPy array of type T provided by the user's module in the rest of my app that requires an IList<T>? Edit To clarify, IronPython exposes any Python enumerable of objects of type T as an IEnumerable<T> or an IList<T>. I'm not sure if NumPy arrays fit in this category. I would rather not have to call .tolist() on the NumPy array as the arrays may be quite large.

    Read the article

  • Ninject Given Path's format is not supported

    - by David Osborn
    The Ninject initialization works fine when i run my application directly from VS2010, but if I deploy the application to our custom "plugin" environment I get this error when I run the app and it tries to initialize Ninject. Error during initialization The given path's format is not supported. ERROR : The given path's format is not supported. Type : NotSupportedException Location: System.String CanonicalizePath(System.String, Boolean) Stack Trace: at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) at System.IO.Path.GetFullPath(String path) at Ninject.Modules.ModuleLoader.NormalizePath(String path) at Ninject.Modules.ModuleLoader.GetFilesMatchingPattern(String pattern) at Ninject.Modules.ModuleLoader.b_0(String pattern) at System.Linq.Enumerable.d_142.MoveNext() at System.Linq.Lookup2.Create[TSource](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.GroupedEnumerable3.GetEnumerator() at Ninject.Modules.ModuleLoader.LoadModules(IEnumerable1 patterns) at Ninject.KernelBase.Load(IEnumerable`1 filePatterns) at Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules) at Ninject.KernelBase..ctor(INinjectModule[] modules) at MyApp.Ioc.ResolveType.Initialize() at MyApp.Program.Run()

    Read the article

  • How to deal with array of checkbox values in Ruby 1.9.1?

    - by Ola Tuvesson
    In Ruby 1.9.1 strings are no longer enumerable and string.each is undefined. This causes a problem when parsing values for an array of generated checkboxes since the field value, when submitted, becomes an array of strings. For example: <% for map in Map.find(:all) %> <%= check_box_tag "listing[map_ids][]", map.id %> <%= map.title %> <% end %> This will result in an error, undefined method `each' for "1":String, in process_parameter_filter because map_ids is being passed as "map_ids"=["1","2"] (if checkboxes with values 1 and 2 have been checked that is). What is the recommended way to fix this?

    Read the article

  • Method synonyms in Ruby

    - by Max
    I'm familiarizing myself with Ruby and it's the first time I see synonyms for methods in the standard library. For now I've found the ones in the Enumerable module: collect <- map detect <- find include <- member etc. Probably other modules contains synonymic methods too. Why are they there? Is it some kind of backward compatibility? Or is it a feature of the language, so the programmer can choose between different options depending on the context to make the program look like plain English?

    Read the article

  • Equality Comparison with Multiple Instances/IEqualityComparer problems in LINQ

    - by Stacey
    This is similar to my last question; but from a different angle. http://stackoverflow.com/questions/2792393/see-if-item-exists-once-in-enumerable-linq Given the following set of items, and lists containing them... Item 1 Item 2 Item 3 Item 4 Item 5 class Item { string Name { get; set; } } List<Item> available = new List<Item>() { Item 1 Item 1 Item 2 Item 3 Item 5 } List<Item> selected = new List<Item>() { Item 1 Item 2 Item 3 } I need to make a third List that has everything from "available", except what is in "selected". However 'Item 1' is in 'available' twice, but only in 'selected' once. Since they are instances of the same item, I am having trouble figuring out the appropriate logic to accomodate this. The final array should look like... List<Item> selectable = new List<Item>() { Item 1 Item5 }

    Read the article

  • ASP.NET MVC 3 Linq uppercase or lowercase database search

    - by user1495557
    I need immediate help. ): and i know little english. ASP.NET MVC 3 Linq uppercase or lowercase contains search Example: string metin="baris"; var IcerikAra = (from icerik in Context.dbDokumanEditor join kategori in Context.dbDokumanKategori on icerik.KategoriID equals kategori.KategoriID where icerik.Icerik.toLower().Contains(metin) select new { KategoriID=kategori. KategoriAd=kategori.KategoriAd }).ToList(); Exception: StackTrace: at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommandentityCommand, CommandBehavior behavior) at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Plus.Areas.DokumanEditor.Controllers.DokumanController.DokumanIcerikAramaBaslat(String metin) Error Message: An error occurred while executing the command definition. See the inner exception for details. thanks..

    Read the article

  • C# LINQ Where Predicate Type Arguments

    - by blu
    I have an XElement with values for mock data. I have an expression to query the xml: Expression<Func<XElement, bool>> simpleXmlFunction = b => int.Parse(b.Element("FooId").Value) == 12; used in: var simpleXml = xml.Elements("Foo").Where(simpleXmlFunction).First(); The design time error is: The type arguments for method 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly' The delegate supplied to Where should take in an XElement and return a bool, marking if the item matches the query, I am not sure how to add anything more to the delegate or the where clause to mark the type. Also, the parallel method for the real function against the Entity Framework does not have this issue. What is not correct with the LINQ-to-XML version?

    Read the article

  • Quickly retrieve the subset of properties used in a huge collection in C#

    - by ccornet
    I have a huge Collection (which I can cast as an enumerable using OfType<()) of objects. Each of these objects has a Category property, which is drawn from a list somewhere else in the application. This Collection can reach sizes of hundreds of items, but it is possible that only, say, 6/30 of the possible Categories are actually used. What is the fastest method to find these 6 Categories? The size of the huge Collection discourages me from just iterating across the entire thing and returning all unique values, so is there a faster method of accomplishing this? Ideally I'd collect the categories into a List.

    Read the article

  • What's the best example of pure show-off code you've seen?

    - by Damovisa
    Let's face it, programmers can be show-offs. I've seen a lot of code that was only done a particular way to prove how smart the person who wrote it was. What's the best example of pure show-off code you've seen (or been responsible for) in your time? For me, it'd have to be the guy who wrote FizzBuzz in one line on a whiteboard during a programming interview. Not really that impressive in the scheme of things, but completely unnecessary and pure, "look-what-I-can-do". I've lost the original code, but I think it was something like this (linebreaks for readability): Enumerable.Range(1,100).ToList().ForEach( n => Console.WriteLine( (n%3==0) ? (n%5==0) ? "FizzBuzz" : "Fizz" : (n%5==0) ? "Buzz" : n ) );

    Read the article

  • LINQ - Contains with anonymous type

    - by Marlos
    When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1 where (t1.COLUMN_A == 1) select new { t1.COLUMN_B, t1.COLUMN_C }); var rows2 = (from t2 in db.TABLE2 where (rows1.Contains(t2.COLUMN_A)) select t2; I got the following error: The type arguments for method 'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable, TSource)' cannot be inferred from the usage. Try specifying the type arguments explicitly. I need to filter the first result by COLUMN_B, but I don't know how. Is there a way to filter it?

    Read the article

  • Extraction Event

    - by Anicho
    So I have the following code: public override void Extract(object sender, ExtractionEventArgs e) { if (e.Response.HtmlDocument != null) { var myParam = e.Request.QueryStringParameters.Where(parameter => parameter.Name == QueryName).Select(parameter => parameter.Value).Distinct(); myParam. // add the extracted value to the web performance test context e.WebTest.Context.Add(this.ContextParameterName, myParam.ToString()); e.Success = true; return; } // If the extraction fails, set the error text that the user sees e.Success = false; e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found: {0}", QueryName); } It's returning: System.Linq.Enumerable+<DistinctItem>d_81`1[system.string] I am expecting something along the lines of: 0152-1231-1231-123d My question is how do I extract the querystring's actual value from extractioneventargs. They say it's possible, but I have no idea.

    Read the article

  • Problem while configuring the file Delimeter("\t") in app.config(C#3.0)

    - by Newbie
    In my app.config file I made the setting like the following <add key = "Delimeter" value ="\t"/> Now while accessing the above from the program by using the below code string delimeter = ConfigurationManager.AppSettings["FileDelimeter"].ToString(); StreamWriter streamWriter = null; streamWriter = new StreamWriter(fs); streamWriter.BaseStream.Seek(0, SeekOrigin.End); Enumerable .Range(0, outData.Length) .ToList().ForEach(i => streamWriter.Write(outData[i].ToString() + delimiter)); streamWriter.WriteLine(); streamWriter.Flush(); I am getting the output as 18804\t20100326\t5.59975381254617\t 18804\t20100326\t1.82599797249479\t But if I directly use "\t" in the delimeter variable I am getting the correct output 18804 20100326 5.59975381254617 18804 20100326 1.82599797249479 I found that while I am specifying the "\t" in the config file, and while reading it into the delimeter variable, it is becoming "\\t" which is the problem. I even tried with but with no luck. I am using C#3.0. Need help

    Read the article

  • Why am I getting "Collection was modified; enumeration operation may not execute" when not modifying

    - by ccornet
    I have two collections of strings: CollectionA is a StringCollection property of an object stored in the system, while CollectionB is a List generated at runtime. CollectionA needs to be updated to match CollectionB if there are any differences. So I devised what I expected to be a simple LINQ method to perform the removal. var strDifferences = CollectionA.Where(foo => !CollectionB.Contains(foo)); foreach (var strVar in strDifferences) { CollectionA.Remove(strVar); } But I am getting a "Collection was modified; enumeration operation may not execute" error on strDifferences... even though it is a separate enumerable from the collection being modified! I originally devised this explicitly to evade this error, as my first implementation would produce it (as I was enumerating across CollectionA and just removing when !CollectionB.Contains(str)). Can anyone shed some insight into why this enumeration is failing?

    Read the article

  • Calculating holidays

    - by Ralph Shillington
    A number of holidays move around from year to year. For example, in Canada Victoria day (aka the May two-four weekend) is the Monday before May 25th, or Thanksgiving is the 2nd Monday of October (in Canada). I've been using variations on this Linq query to get the date of a holiday for a given year: var year = 2011; var month = 10; var dow = DayOfWeek.Monday; var instance = 2; var day = (from d in Enumerable.Range(1,DateTime.DaysInMonth(year,month)) let sample = new DateTime(year,month,d) where sample.DayOfWeek == dow select sample).Skip(instance-1).Take(1); While this works, and is easy enough to understand, I can imagine there is a more elegant way of making this calculation versus this brute force approach. Of course this doesn't touch on holidays such as Easter and the many other lunar based dates.

    Read the article

  • Select a data template by item type programatically in WPF

    - by Michael Stoll
    Hi all, unfortunately the WPF ToolbarTray does not support binding to a collection of ToolbarViewModels (Correct me, if I'm wrong). Thus I want to create the Toolbars programmatically. So there are two tasks, which I don't know how to do: Select the data template based on the item type. Instantiate the data template as toolbar Both should do the same as WPF does, when we use ItemsControl with an enumerable content and empty template. I used reflector to anaylse what WPF does. Task 1 is done by FrameworkElement.FindTemplateResourceInternal, but this is internal, and I couldn't find any public methods to acomplish the task. Of course one could enumerate all resources and match the data template data type property, but this seems sub-optimal. Who know's how to acomplish these tasks?

    Read the article

  • Type or namespace name could not be found

    - by Pandiya Chendur
    I use this: public IQueryable<MaterialsView> FindAllMaterials() { var materials = from m in db.Materials join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id select new MaterialsView { MatId = m.Mat_Name, MesName = Mt.Name, MesType = m.Mat_Type }; return materials; } It gives me the following errors: The type or namespace name MaterialsView could not be found (are you missing a using directive or an assembly reference?) Cannot implicitly convert type System.Collections.Generic.IEnumerable<MaterialsView> to System.Linq.IQueryable<MaterialsView>. An explicit conversion exists (are you missing a cast?) The type arguments for method System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>) cannot be inferred from the usage. Try specifying the type arguments explicitly. I have googled it and found this SO question but it doesn't help. What's wrong?

    Read the article

  • InvalidOperationException sequence contains more than one element even when only one element

    - by user310256
    I have three tables, tblCompany table, tblParts table and a link table between them tblLinkCompanyParts. Since tblLinkCompanyParts is a link table so the columns that it has are LinkCompanyPartID(primary key), CompanyID from tblCompany table and PartID from tblParts as foreign keys. I have tied them up in the dbml file. In code if I write LinkCompanyParts.Parts (where LinkCompanyParts is an object of the tblLinkCompanyParts type) to get to the corresponding Part object I get the "InvalidOperationException: Sequence constains more than one element". I have looked at the data in the database and there is only one Parts record associated with the LinkCompanyPartID. The stack trace reads like at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) at System.Data.Linq.EntityRef`1.get_Entity() at ... I read about SingleOrDefault vs FirstOrDefault but since the link table should have a one-one mapping therefore I think SingleOrDefault should work and besides "SingleOrDefault" statement is being generated behind the scenes in the designer.cs file at the following line return this._Part.Entity; Any ideas?

    Read the article

  • Unable to type cast <AnonymousType#1> to <WindowsFormsApplication1.Attributes> [ C#3.0 ]

    - by Newbie
    I have List<Attributes> la = new List<Attributes>(); la = (from t in result let t1 = t.AttributeCollection from t2 in t1 where t2.AttributeCode.Equals(attributeType) let t3 = t2.TimeSeriesData from k in t3.ToList() where k.Key.Equals(startDate) && k.Key.Equals(endDate) select new { AttributeCode = attributeType, TimeSeriesData = fn(k.Key, k.Value.ToString()) }).ToList<Attributes>(); I am getting the error: 'System.Collections.Generic.IEnumerable<AnonymousType#1>' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments I understood tye error meaning but how to type cast it. I have used var and then iterating over it got the result. But without that any other way by which I can do it? Using C# 3.0 Thanks

    Read the article

  • c# Delegates, Events and Lambda Expr for new students

    - by MarkP
    I've been asked by my pointy haired boss to educate our new co-ops (interns) in the ways of C#. I have roughly ~30mins to cover the topics of Delegates, Events and Lambda Expressions. The time restriction is rather tight and the topics are broad. Since I'm not a C# guru, I would like some hints and pointers. Since my time is short, what points should I cover with respect to the three topics listed above? What are some good Do's and Dont's when using those three things? I might have time for a short Lambda Expr demo. What is the most common use of LExpr (probably a Select().Where() statement on an enumerable??) that I could demo? Thanks. EDIT: The students have working knowledge of C++ and Java.

    Read the article

  • How can I evaluate a deferred Linq statement when debugging?

    - by DanO
    I'm debugging in VS2010, and I want to inspect a string value but all I can get the debugger to show me (through watches, hovering, locals, etc.) is: "System.Linq.Enumerable+<TakeIterator>d__3a`1[System.Char]" I don't care if there are side effects from premature evaluation or whatever, I just want to see what the expression would evaluate to if I evaluate it right now at the current breakpoint. How is this done? Also can I change my code in such a way that it evaluates earlier? Not that I care when I'm not debugging... but just wondering. In case it is relevant... (I doubt it.) I'm stuffing a new entity object before saving it to the database... some fields are assigned with LINQ statements, I'm not sure when they get evaluated under the covers of EF. The DB update fails with 'string or binary data would be truncated... So I'm trying to find the too-long field.

    Read the article

  • Exploding a range of dates with LINQ

    - by Robert Gowland
    If I have a pair of dates, and I want to generate a list of all the dates between them (inclusive), I can do something like: System.DateTime s = new System.DateTime(2010, 06, 05); System.DateTime e = new System.DateTime(2010, 06, 09); var list = Enumerable.Range(0, (e - s).Days) .Select(value => s.AddDays(value)); What I'm stuck on is that I've got a list of pairs of dates that I want to explode into a list of all the dates between them. Example: {2010-05-06, 2010-05-09}, {2010-05-12, 2010-05-15} should result in {2010-05-06, 2010-05-07, 2010-05-08, 2010-05-09, 2010-05-12, 2010-05-13, 2010-05-14, 2010-05-15} Note the pairs of dates are guaranteed not to overlap each other.

    Read the article

  • How to find hidden properties/methods in Javascript objects?

    - by ramanujan
    I would like to automatically determine all of the properties (including the hidden ones) in a given Javascript object, via a generalization of this function: function keys(obj) { var ll = []; for(var pp in obj) { ll.push(pp); } return ll; } This works for user defined objects but fails for many builtins: repl> keys({"a":10,"b":2}); // ["a","b"] repl> keys(Math) // returns nothing! Basically, I'd like to write equivalents of Python's dir() and help(), which are really useful in exploring new objects. My understanding is that only the builtin objects have hidden properties (user code evidently can't set the "enumerable" property till HTML5), so one possibility is to simply hardcode the properties of Math, String, etc. into a dir() equivalent (using the lists such as those here). But is there a better way?

    Read the article

  • knockout.js with optionsValue and value

    - by Mike Flynn
    Is there a way to keep the value binding to the object, but have the optionsValue be a property on the object. As of now if I specify both, the optionsValue property that is selected will populate the value binding. Id like to keep the object intact in the observable, but specify what value to be set in the select list value. This way a form submit will send the optionsValue I chose. @Html.DropDownListFor(q => q.DivisionId, new SelectList(Enumerable.Empty<string>()), new { data_bind="options: divisions, optionsText: 'Name', optionsValue: 'Id', value: division, optionsCaption: ' - '" }) function AddCrossPoolGameDialog() { var self = this; self.divisions = ko.observableArray([]); self.division = ko.observable(); self.awayDivisionTeams = ko.computed(function () { var division = ko.utils.arrayFirst(self.divisions(), function(item) { return self.division.Name() == item.Name; }); if (division) { return division.DivisionTeamPools; } return []; }); }

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9  | Next Page >