Search Results

Search found 586 results on 24 pages for 'ilist'.

Page 2/24 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • APS.NET MVC Ajax: Passing a IList from the View to the Controller

    - by Bpimenta
    I need to pass the grid rows from the view to the controller using POST. The idea is to pass an IList of objects (people) that have the following structure: String Name String Address String ID I want to read the data from the JQGrid and pass it to the controller to fill the IList. I'm trying to build the data object to pass through the Ajax data parameter. Here is the Javascript code: $("#saveButton").click( function() { var returnData = '{'; var existingIDs = $('#listPeople').getDataIDs(); if (idsPeople.length > 0) { for (i=0;i<idsPeople.length;i++) { //Trying to build the obejct data ret = ret + '"people['+ i +'].Name":' $('#listPeople').getRowData(idsPeople[i]).Name + ','; ret = ret + '"people['+ i +'].Address":' $('#listPeople').getRowData(idsPeople[i]).Address+ ','; ret = ret + '"people['+ i +'].Id":' $('#listPeople').getRowData(idsPeople[i]).Id+ ','; //If it has more than one element if (idsPeople.length>1 && (i+1)<idsPeople.length) { ret = ret + ','; } } } ret = ret + '}'; My Ajax function for sending: var url_all = '<%=Url.Action("SaveData") %>; $.ajax({ type: "POST", url: url_all, data: ret, dataType: "json", success: function(){ alert("OK"); }, error: function(){ alert("Error: check SaveData"); } }); My controller: public ActionResult SaveData(IList<PeopleHeader> people){ // using debug to know if "people" variable has any values return Json(true); } The problem I'm getting is an error: "System.NotSupportedException: Fixed size collection", and no data is being delivered. I think my problem relies on creating the object... is there any simpler way of doing this procedure? Thanks in advance,

    Read the article

  • NHibernate: Mapping IList property

    - by Anry
    I have a table Order, Transaction, Payment. Class Order has the properties: public virtual Guid Id { get; set; } public virtual DateTime Created { get; set; } ... I added properties: public virtual IList<Transaction> Transactions { get; set; } public virtual IList<Payment> Payments { get; set; } These properties contain a record of tables [Transaction] and [Payment]. How to keep these lists in the database?

    Read the article

  • Does a Collection<T> wrap an IList<T> or enumerate over the IList<T>?

    - by Brian Triplett
    If I am exposing a internal member via a Collection property via: public Collection<T> Entries { get { return new Collection<T>(this.fieldImplimentingIList<T>); } } When this property is called what happens? For example what happens when the following lines of code are called: T test = instanceOfAbove.Entries[i]; instanceOfAbove[i] = valueOfTypeT; It's clear that each time this property is called a new reference type is created but what acctually happens? Does it simply wrap the IList<T> underneath, does it enumerate over the IList<T> and to create a new Collection<T> instance? I'm concerned about performance if this property is used in a for loop.

    Read the article

  • Does a System.Collection.Collection<T> wrap a IList<T> or enumerate over the IList<T> or simply wra

    - by Brian Triplett
    If I am exposing a internal member via a Collection property via: public Collection<T> Entries { get { return new Collection<T>(this.fieldImplimentingIList<T>); } } When this property is called what happens? For example what happens when the following lines of code are called: T test = instanceOfAbove.Entries[i]; instanceOfAbove[i] = valueOfTypeT; It's clear that each time this property is called a new reference type is created but what acctually happens? Does it simply wrap the IList<T> underneath, does it enumerate over the IList<T> and to create a new Collection<T> instance? I'm concerned about performance if this property is used in a for loop.

    Read the article

  • Binding an Ilist to datagridview containing another object in a field

    - by JaSk
    I have pretty much the same problem as this question http://stackoverflow.com/questions/970741 but in windows forms, can anyone help me solve it? this is my code, so you don't have to check the other question: public class Material { public virtual int id { get; private set; } public virtual string nombre { get; set; } public virtual string unidad { get; set; } public virtual Categorias Categoria { get; set; } public virtual IList Materiales { get; set; } public Material() { Materiales = new List<Materiales>(); } public virtual void AddMateriales(Materiales materiales) { materiales.Material = this; this.Materiales.Add(materiales); } } as you can see I have an object within the IList so when I use the List as the data source for a datagridview I get a object.categoria where I want to get the Categoria.Name property, can anyone help me?. Thanks

    Read the article

  • Convert From Custom List to List of String

    - by Paul Johnson
    Hi all I have the following code: Public Shared Function ConvertToString(ByVal list As IList) As String Dim strBuilder = New System.Text.StringBuilder() Dim item As Object For Each item In list strBuilder.Append(obj.ToString()) strBuilder.Append(",") Next Return strBuilder.ToString(strBuilder.Length - 1) End Function The intention is to convert an IList of custom objects to a string equivalent comprising each element in the Ilist. Unfortunately I can't seem to find a way to get the underlying data of the custom object, and of course as in the above example, using object simply gives me a string of types definitions, rather than access to the underlying data. Any assistance much appreciated. Paul.

    Read the article

  • IList<T> versus Collection<T> as property

    - by Brian Triplett
    I have a class with a internal array field. I want to expose this array as a property, such that it maintains as much funtionallity of the orginal array but does not violate abstraction by exposing the array directly. What are the various methods and pros and cons? I'm thinking specifically about IList<T> or Colleciton<T>

    Read the article

  • Linq to SQL, Repository, IList and Persist All

    - by Dr. Zim
    This discusses a repository which returns IList that also uses Linq to SQL as a DAL. Once you do a .ToList(), IQueryable object is gone once you exit the Repository. This means that I need to send the objects back in to the Repo methods .Create(Model model), .Update(Model model), and .Delete(int ID). Assuming that is correct, how do you do the PersistAll()? For example, if you did the following, how would you code that in the repository? Changed a single string property in the object Called .Update(object); Changed a different string property in the object Called .Update(object); Called .PersistAll(), which would update the database with both changed strings. How would you associate the objects in the Repository parameters with the objects in the Linq to Sql data context, especially over multiple calls? I am sure this is a standard thing. Links to examples on the web would be great!

    Read the article

  • Selecting a sequence of elements from the IList

    - by KhanS
    I have a IList. where the object PersonDetails consists of the persons name, address and phone number. The list consists of more than 1000 person details. I would like to display 50 PersonDetails per page. Is there a way to select only 50 elements from the list, and return them. For example. myList.select(1,50) myList.select(51, 100) I am able to select only first 50 by using. myList.Take(50); The entire list is at the wcf service, and i would like to get only fifty elements at a time.

    Read the article

  • Mapping an instance of IList in NHibernate

    - by Martin Kirsche
    I'm trying to map a parent-child relationship using NHibernate (2.1.2), MySql.Data (6.2.2) and MySQL Server (5.1). I figured out that this must be done using a <bag> in the mapping file. I build a test app which is running without yielding any errors and is doing an insert for each entry but somehow the foreign key inside the children table (ParentId) is always empty (null). Here are the important parts of my code... Parent public class Parent { public virtual int Id { get; set; } public virtual IList<Child> Children { get; set; } } <class name="Parent"> <id name="Id"> <generator class="native"/> </id> <bag name="Children" cascade="all"> <key column="ParentId"/> <one-to-many class="Child"/> </bag> </class> Child public class Child { public virtual int Id { get; set; } } <class name="Child"> <id name="Id"> <generator class="native"/> </id> </class> Program using (ISession session = sessionFactory.OpenSession()) { session.Save( new Parent() { Children = new List<Child>() { new Child(), new Child() } }); } Any ideas what I did wrong?

    Read the article

  • Get ViewData IList back on postback in ASP.NET MVC

    - by Thomas
    I have the following in my view: <%using (Html.BeginForm()) {%> <% foreach (var item in Model.Cart) { %> <div> <%= Html.TextBox("Cart.Quantity", item.Quantity, new { maxlength = "2" })%> <%= Html.Hidden("Cart.ItemID", item.ItemID)%> </div> <% } %> <input name="update" type="image" src="image.gif" /> <% } % I then have this code in my controller: public ActionResult Index() { CartViewData cartViewData = new CartViewData(); IList<Item> items = ItemManager.GetItems(); cartViewData.Cart = items; return View("Index", cartViewData); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(CartViewData cartViewData) { // cartviewData is null } Is there a way to grab the List on the postback to see if the values in the textboxes have changed? Thanks Below is a simplified example since it was requested: <% for (int i = 0; i < Model.Cart.Count; i++ ) { %> <a href="javascript:void(0);" onclick="removeItem(<%= Model.Cart[i].ShoppingCartItemID %>);">Remove</a> <% } %> Hope this helps.

    Read the article

  • List.ForEach method and collection interfaces

    - by tyndall
    In .NET 3.5 List< gains a ForEach method. I notice this does not exist on IList< or IEnumerable< what was the thinking here? Is there another way to do this? Nice and simple short way to do this? I ask because I was at a talk where the speaker said always use the more general interfaces. But why would I use IList< as a return type if I want to be able to turn around and use ForEach? Then I would just end up casting it back to a List<.

    Read the article

  • Using a custom IList obtained through NHibernate

    - by Abu Dhabi
    Hi.I'm trying to write a web page in .NET, using C# and NHibernate 2.1. The pertinent code looks like this: var whatevervar = session.CreateSQLQuery("select thread_topic, post_time, user_display_name, user_signature, user_avatar, post_topic, post_body from THREAD, [USER], POST, THREADPOST where THREADPOST.thread_id=" + id + " and THREADPOST.thread_id=THREAD.thread_id and [USER].user_id=POST.user_id and POST.post_id=THREADPOST.post_id ORDER BY post_time;").List(); (I have tried to use joins in HQL, but then fell back on this query, due to HQL's unreadability.) The problem is that I'm getting a result that is incompatible with a repeater. When I try this: posts.DataSource = whatevervar.; posts.DataBind(); ...I get this: DataBinding: 'System.Object[]' does not contain a property with the name 'user_avatar'. In an earlier project, I used LINQ to SQL for this same purpose, and it looked like so: var whatevervar = from threads in context.THREADs join threadposts in context.THREADPOSTs on threads.thread_id equals threadposts.thread_id join posts1 in context.POSTs on threadposts.post_id equals posts1.post_id join users in context.USERs on posts1.user_id equals users.user_id orderby posts1.post_time where threads.thread_id == int.Parse(id) select new { threads.thread_topic, posts1.post_time, users.user_display_name, users.user_signature, users.user_avatar, posts1.post_body, posts1.post_topic }; That worked, and now I want to do the same with NHibernate. Unfortunately, I don't know how to make the repeater recognize the fields of the result of the query. Thanks in advance!

    Read the article

  • IList<Item> Collection Class accessing database

    - by Mike
    Hi, I have a database with Users. Users have Items. These Items can change actively. How do you access the items in a collection type format? For the user, I fill all the user properties at the time of instantiation. If I load the user's items at the time of the instantiation, and the items change, they will have old data. I was thinking, maybe I need an ItemCollection class and have that a field/property apart of the user class, that way to traverse all the user's items I could use a foreach loop. So, my question is, what is the best practice/best way of accessing the items from a database using some sort of collection? On accessing the particular Item, it needs to get the latest database information, and when the user does do a foreach loop, the latest item information must be available. I.e. What I'm trying to do Console.WriteLine(User.Items[3].ID); returns 5. //this updates the item information and saves it to the database. User.Items[3].ID = 13; //Add a new item to the database. User.Items.Add(new Item { id = 17}); foreach (Item item in User.Items) { //this would traverse all items in the database. //not some cached copy at the time of instantiation of the user. }

    Read the article

  • How to perform a binary search on IList<T>?

    - by Daniel Brückner
    Simple question - given an IList<T> how do you perform a binary search without writing the method yourself and without copying the data to a type with build-in binary search support. My current status is the following. List<T>.BinarySearch() is not a member of IList<T> There is no equivalent of the ArrayList.Adapter() method for List<T> IList<T> does not inherit from IList, hence using ArrayList.Adapter() is not possible I tend to believe that is not possible with build-in methods, but I cannot believe that such a basic method is missing from the BCL/FCL. If it is not possible, who can give the shortest, fastest, smartest, or most beatiful binary search implementation for IList<T>? UPDATE We all know that a list must be sorted before using binary search, hence you can assume that it is. But I assume (but did not verify) it is the same problem with sort - how do you sort IList<T>? CONCLUSION There seems to be no build-in binary search for IList<T>. One can use First() and OrderBy() LINQ methods to search and sort, but it will likly have a performance hit. Implementing it yourself (as an extension method) seems the best you can do.

    Read the article

  • Comparison operators not supported for type IList when Paging data in Linq to Sql

    - by Dan
    I can understand what the error is saying - it can't compare a list. Not a problem, other than the fact that I don't know how to not have it compare a list when I want to page through a model with a list as a property. My Model: Event : IEvent int Id string Title // Other stuff.. LazyList<EventDate> Dates // The "problem" property Method which pages the data (truncated): public JsonResult JsonEventList(int skip, int take) { var query = _eventService.GetEvents(); // Do some filtering, then page data.. query = query.Skip(skip).Take(take); return Json(query.ToArray()); } As I said, the above is truncated quite a bit, leaving only the main point of the function: filter, page and return JSON'd data. The exception occurs when I enumerate (.ToArray()). The Event object is really only used to list the common objects of all the event types (Meetings, Birthdays, etc - for example). It still implements IEvent like the other types, so I can't just remove the LazyList<EventDate> Dates' property unless I no longer implementIEvent` Anyway, is there a way to avoid this? I don't really want to compare a LazyList when I page, but I do not know how to resolve this issue. Thank you in advance! :)

    Read the article

  • Queue In a C# Ilist

    - by Ricky
    Hello, I have a list with 5 elements...What I want to move foward all elements, removing the last one and add a new value to the first one. Is there any pre-made list methods that do that or help me so? Like a Queue

    Read the article

  • WPF Databinding and Styling based on Data in an item in an IList

    - by Nate Bross
    I have a ListBox bound to a list of Items (for arguement, lets say its got a string and two dates Entered and Done). I would like to make the background color of items in the ListBox have a gray color if the Done DateTime is != DateTime.MinValue. Edit: Should I make a converter? and convert DateTime to a Brush based on the value of the DateTime? Is something like this my best option? or is there a simple Xaml snippet I could use? [ValueConversion(typeof(DateTime), typeof(Brush))] class MyConverter : IValueConverter { ... }

    Read the article

  • A Nondeterministic Engine written in VB.NET 2010

    - by neil chen
    When I'm reading SICP (Structure and Interpretation of Computer Programs) recently, I'm very interested in the concept of an "Nondeterministic Algorithm". According to wikipedia:  In computer science, a nondeterministic algorithm is an algorithm with one or more choice points where multiple different continuations are possible, without any specification of which one will be taken. For example, here is an puzzle came from the SICP: Baker, Cooper, Fletcher, Miller, and Smith live on different floors of an apartment housethat contains only five floors. Baker does not live on the top floor. Cooper does not live onthe bottom floor. Fletcher does not live on either the top or the bottom floor. Miller lives ona higher floor than does Cooper. Smith does not live on a floor adjacent to Fletcher's.Fletcher does not live on a floor adjacent to Cooper's. Where does everyone live? After reading this I decided to build a simple nondeterministic calculation engine with .NET. The rough idea is that we can use an iterator to track each set of possible values of the parameters, and then we implement some logic inside the engine to automate the statemachine, so that we can try one combination of the values, then test it, and then move to the next. We also used a backtracking algorithm to go back when we are running out of choices at some point. Following is the core code of the engine itself: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--Public Class NonDeterministicEngine Private _paramDict As New List(Of Tuple(Of String, IEnumerator)) 'Private _predicateDict As New List(Of Tuple(Of Func(Of Object, Boolean), IEnumerable(Of String))) Private _predicateDict As New List(Of Tuple(Of Object, IList(Of String))) Public Sub AddParam(ByVal name As String, ByVal values As IEnumerable) _paramDict.Add(New Tuple(Of String, IEnumerator)(name, values.GetEnumerator())) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(1, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(2, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Object, Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(3, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Object, Object, Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(4, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Object, Object, Object, Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(5, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Object, Object, Object, Object, Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(6, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Object, Object, Object, Object, Object, Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(7, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Public Sub AddRequire(ByVal predicate As Func(Of Object, Object, Object, Object, Object, Object, Object, Object, Boolean), ByVal paramNames As IList(Of String)) CheckParamCount(8, paramNames) _predicateDict.Add(New Tuple(Of Object, IList(Of String))(predicate, paramNames)) End Sub Sub CheckParamCount(ByVal count As Integer, ByVal paramNames As IList(Of String)) If paramNames.Count <> count Then Throw New Exception("Parameter count does not match.") End If End Sub Public Property IterationOver As Boolean Private _firstTime As Boolean = True Public ReadOnly Property Current As Dictionary(Of String, Object) Get If IterationOver Then Return Nothing Else Dim _nextResult = New Dictionary(Of String, Object) For Each item In _paramDict Dim iter = item.Item2 _nextResult.Add(item.Item1, iter.Current) Next Return _nextResult End If End Get End Property Function MoveNext() As Boolean If IterationOver Then Return False End If If _firstTime Then For Each item In _paramDict Dim iter = item.Item2 iter.MoveNext() Next _firstTime = False Return True Else Dim canMoveNext = False Dim iterIndex = _paramDict.Count - 1 canMoveNext = _paramDict(iterIndex).Item2.MoveNext If canMoveNext Then Return True End If Do While Not canMoveNext iterIndex = iterIndex - 1 If iterIndex = -1 Then Return False IterationOver = True End If canMoveNext = _paramDict(iterIndex).Item2.MoveNext If canMoveNext Then For i = iterIndex + 1 To _paramDict.Count - 1 Dim iter = _paramDict(i).Item2 iter.Reset() iter.MoveNext() Next Return True End If Loop End If End Function Function GetNextResult() As Dictionary(Of String, Object) While MoveNext() Dim result = Current If Satisfy(result) Then Return result End If End While Return Nothing End Function Function Satisfy(ByVal result As Dictionary(Of String, Object)) As Boolean For Each item In _predicateDict Dim pred = item.Item1 Select Case item.Item2.Count Case 1 Dim p1 = DirectCast(pred, Func(Of Object, Boolean)) Dim v1 = result(item.Item2(0)) If Not p1(v1) Then Return False End If Case 2 Dim p2 = DirectCast(pred, Func(Of Object, Object, Boolean)) Dim v1 = result(item.Item2(0)) Dim v2 = result(item.Item2(1)) If Not p2(v1, v2) Then Return False End If Case 3 Dim p3 = DirectCast(pred, Func(Of Object, Object, Object, Boolean)) Dim v1 = result(item.Item2(0)) Dim v2 = result(item.Item2(1)) Dim v3 = result(item.Item2(2)) If Not p3(v1, v2, v3) Then Return False End If Case 4 Dim p4 = DirectCast(pred, Func(Of Object, Object, Object, Object, Boolean)) Dim v1 = result(item.Item2(0)) Dim v2 = result(item.Item2(1)) Dim v3 = result(item.Item2(2)) Dim v4 = result(item.Item2(3)) If Not p4(v1, v2, v3, v4) Then Return False End If Case 5 Dim p5 = DirectCast(pred, Func(Of Object, Object, Object, Object, Object, Boolean)) Dim v1 = result(item.Item2(0)) Dim v2 = result(item.Item2(1)) Dim v3 = result(item.Item2(2)) Dim v4 = result(item.Item2(3)) Dim v5 = result(item.Item2(4)) If Not p5(v1, v2, v3, v4, v5) Then Return False End If Case 6 Dim p6 = DirectCast(pred, Func(Of Object, Object, Object, Object, Object, Object, Boolean)) Dim v1 = result(item.Item2(0)) Dim v2 = result(item.Item2(1)) Dim v3 = result(item.Item2(2)) Dim v4 = result(item.Item2(3)) Dim v5 = result(item.Item2(4)) Dim v6 = result(item.Item2(5)) If Not p6(v1, v2, v3, v4, v5, v6) Then Return False End If Case 7 Dim p7 = DirectCast(pred, Func(Of Object, Object, Object, Object, Object, Object, Object, Boolean)) Dim v1 = result(item.Item2(0)) Dim v2 = result(item.Item2(1)) Dim v3 = result(item.Item2(2)) Dim v4 = result(item.Item2(3)) Dim v5 = result(item.Item2(4)) Dim v6 = result(item.Item2(5)) Dim v7 = result(item.Item2(6)) If Not p7(v1, v2, v3, v4, v5, v6, v7) Then Return False End If Case 8 Dim p8 = DirectCast(pred, Func(Of Object, Object, Object, Object, Object, Object, Object, Object, Boolean)) Dim v1 = result(item.Item2(0)) Dim v2 = result(item.Item2(1)) Dim v3 = result(item.Item2(2)) Dim v4 = result(item.Item2(3)) Dim v5 = result(item.Item2(4)) Dim v6 = result(item.Item2(5)) Dim v7 = result(item.Item2(6)) Dim v8 = result(item.Item2(7)) If Not p8(v1, v2, v3, v4, v5, v6, v7, v8) Then Return False End If Case Else Throw New NotSupportedException End Select Next Return True End FunctionEnd Class    And now we can use the engine to solve the problem we mentioned above:   Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--Sub Test2() Dim engine = New NonDeterministicEngine() engine.AddParam("baker", {1, 2, 3, 4, 5}) engine.AddParam("cooper", {1, 2, 3, 4, 5}) engine.AddParam("fletcher", {1, 2, 3, 4, 5}) engine.AddParam("miller", {1, 2, 3, 4, 5}) engine.AddParam("smith", {1, 2, 3, 4, 5}) engine.AddRequire(Function(baker) As Boolean Return baker <> 5 End Function, {"baker"}) engine.AddRequire(Function(cooper) As Boolean Return cooper <> 1 End Function, {"cooper"}) engine.AddRequire(Function(fletcher) As Boolean Return fletcher <> 1 And fletcher <> 5 End Function, {"fletcher"}) engine.AddRequire(Function(miller, cooper) As Boolean 'Return miller = cooper + 1 Return miller > cooper End Function, {"miller", "cooper"}) engine.AddRequire(Function(smith, fletcher) As Boolean Return smith <> fletcher + 1 And smith <> fletcher - 1 End Function, {"smith", "fletcher"}) engine.AddRequire(Function(fletcher, cooper) As Boolean Return fletcher <> cooper + 1 And fletcher <> cooper - 1 End Function, {"fletcher", "cooper"}) engine.AddRequire(Function(a, b, c, d, e) As Boolean Return a <> b And a <> c And a <> d And a <> e And b <> c And b <> d And b <> e And c <> d And c <> e And d <> e End Function, {"baker", "cooper", "fletcher", "miller", "smith"}) Dim result = engine.GetNextResult() While Not result Is Nothing Console.WriteLine(String.Format("baker: {0}, cooper: {1}, fletcher: {2}, miller: {3}, smith: {4}", result("baker"), result("cooper"), result("fletcher"), result("miller"), result("smith"))) result = engine.GetNextResult() End While Console.WriteLine("Calculation ended.")End Sub   Also, this engine can solve the classic 8 queens puzzle and find out all 92 results for me.   Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--Sub Test3() ' The 8-Queens problem. Dim engine = New NonDeterministicEngine() ' Let's assume that a - h represents the queens in row 1 to 8, then we just need to find out the column number for each of them. engine.AddParam("a", {1, 2, 3, 4, 5, 6, 7, 8}) engine.AddParam("b", {1, 2, 3, 4, 5, 6, 7, 8}) engine.AddParam("c", {1, 2, 3, 4, 5, 6, 7, 8}) engine.AddParam("d", {1, 2, 3, 4, 5, 6, 7, 8}) engine.AddParam("e", {1, 2, 3, 4, 5, 6, 7, 8}) engine.AddParam("f", {1, 2, 3, 4, 5, 6, 7, 8}) engine.AddParam("g", {1, 2, 3, 4, 5, 6, 7, 8}) engine.AddParam("h", {1, 2, 3, 4, 5, 6, 7, 8}) Dim NotInTheSameDiagonalLine = Function(cols As IList) As Boolean For i = 0 To cols.Count - 2 For j = i + 1 To cols.Count - 1 If j - i = Math.Abs(cols(j) - cols(i)) Then Return False End If Next Next Return True End Function engine.AddRequire(Function(a, b, c, d, e, f, g, h) As Boolean Return a <> b AndAlso a <> c AndAlso a <> d AndAlso a <> e AndAlso a <> f AndAlso a <> g AndAlso a <> h AndAlso b <> c AndAlso b <> d AndAlso b <> e AndAlso b <> f AndAlso b <> g AndAlso b <> h AndAlso c <> d AndAlso c <> e AndAlso c <> f AndAlso c <> g AndAlso c <> h AndAlso d <> e AndAlso d <> f AndAlso d <> g AndAlso d <> h AndAlso e <> f AndAlso e <> g AndAlso e <> h AndAlso f <> g AndAlso f <> h AndAlso g <> h AndAlso NotInTheSameDiagonalLine({a, b, c, d, e, f, g, h}) End Function, {"a", "b", "c", "d", "e", "f", "g", "h"}) Dim result = engine.GetNextResult() While Not result Is Nothing Console.WriteLine("(1,{0}), (2,{1}), (3,{2}), (4,{3}), (5,{4}), (6,{5}), (7,{6}), (8,{7})", result("a"), result("b"), result("c"), result("d"), result("e"), result("f"), result("g"), result("h")) result = engine.GetNextResult() End While Console.WriteLine("Calculation ended.")End Sub (Chinese version of the post: http://www.cnblogs.com/RChen/archive/2010/05/17/1737587.html) Cheers,  

    Read the article

  • What's the best way to use hamcrest-AS3 to test for membership in an IList?

    - by Chris R
    I'm using Flex 3.3, with hamcrest-as3 used to test for item membership in a list as part of my unit tests: var myList: IList = new ArrayCollection(['a', 'b', 'c']).list; assertThat(myList, hasItems('a', 'b', 'c')); The problem is that apparently the IList class doesn't support for each iteration; for example, with the above list, this will not trace anything: for each (var i: * in myList) { trace (i); } However, tracing either an Array or an ArrayCollection containing the same data will work just fine. What I want to do is (without having to tear apart my existing IList-based interface) be able to treat an IList like an Array or an ArrayCollection for the purposes of testing, because that's what hamcrest does: override public function matches(collection:Object):Boolean { for each (var item:Object in collection) { if (_elementMatcher.matches(item)) { return true; } } return false; } Is this simply doomed to failure? As a side note, why would the IList interface not be amenable to iteration this way? That just seems wrong.

    Read the article

  • Model Binding to a List using non-sequential indexes. Can I access the index later?

    - by Kid A
    I'm following Phil's great tutorial on model binding to a list. I use input names like this: book[5804].title book[5804].author book[1234].title book[1234].author This works well and the data gets back to the model just fine, populating a list of books. What I'm looking for is a way to get access in the model to the index that was used to send the books. I'd like to get that number, "5804." This is because the index is of semantic importance. If I can access it, it saves me from setting another property on the object (book ID). Is there a way to see, either on the FormCollection or on the model after UpdateModel is called, what the index was when it was sent up?

    Read the article

  • Time to start returning IQueryable<T> instead of IList<T> to my Web UI / Web API Layer?

    - by JohnnyO
    I've got a multi-layer application that starts with the repository pattern for all data access and it returns IQueryable to the Services layer. The Services layer, which includes all of the business logic, returns IList to the Controllers (note: I'm using ASP.NET MVC for the UI layer). The benefit of returning IQueryable in the data access layer is that it allows my repositories to be extremely simple and the database queries to be deferred. However, I'm triggering the database queries in my services layer so that my unit tests is more reliable and I don't give flexibility to the Controllers to reshape my queries. However, I've recently encountered several situations where deferring the execution of queries down to the Controllers would have been significantly more performant because the Controllers had to do some projections on the data that was UI specific. Additionally, with the emergence of things like oData, I was starting to wonder if end points (e.g. web UI or web apis) should be working directly with IQueryable. What are your thoughts? Is it time to start returning IQueryable from the services layer to the UI layer? Or stick with IList? This thread here: http://stackoverflow.com/questions/718624/to-return-iqueryablet-or-not-return-iqueryablet seems to vouch for returning IList to the UI layers, but I was wondering if things are changing because of new emerging technologies and techniques.

    Read the article

  • Namespace scoped aliases for generic types in C#

    - by TN
    Let's have a following example: public class X { } public class Y { } public class Z { } public delegate IDictionary<Y, IList<Z>> Bar(IList<X> x, int i); public interface IFoo { // ... Bar Bar { get; } } public class Foo : IFoo { // ... public Bar Bar { get { return null; //... } } } void Main() { IFoo foo; //= ... IEnumerable<IList<X>> source; //= ... var results = source.Select(foo.Bar); } The compiler says: The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly. It's because, it cannot convert Bar to Func<IList<X>, int, IDictionary<Y, IList<Z>>>. It would be great if I could create type namespace scoped type aliases for generic types in C#. Then I would define Bar not as a delegate, but rather I would define it as an namespace scoped alias for Func<IList<X>, int, IDictionary<Y, IList<Z>>>. public alias Bar = Func<IList<X>, int, IDictionary<Y, IList<Z>>>; I could then also define namespace scoped alias for e.g. IDictionary<Y, IList<Z>>. And if used appropriately:), it will make the code more readable. Now I have inline the generic types and the real code is not well readable:( Have you find the same trouble:)? Is there any good reason why it is not in C# 3.0? Or there is no good reason, it's just matter of money and/or time? EDIT: I know that I can use using, but it is not namespace based - not so convenient for my case.

    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

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >