Search Results

Search found 36179 results on 1448 pages for 'generic list'.

Page 95/1448 | < Previous Page | 91 92 93 94 95 96 97 98 99 100 101 102  | Next Page >

  • Create Generic Class Instance from Static Method in a Derived Class

    - by user343547
    I have a class in C# with a template and static method similar to class BClass<T> { public static BClass<T> Create() { return new BClass<T>(); } } From this I derive a class and specify a template parameter to the base class class DClass : BClass<int> { } A problem occurs when I try to use the static method to create an instance of D class Program { static void Main(string[] args) { DClass d = DClass.Create(); } } Gives a compiler error "Cannot implicitly convert type 'Test.BClass<int ' to 'Test.DClass'." Adding the below cast leads to a runtime casting exception. DClass d = (DClass)DClass.Create(); Is there any succint way to allow the static method to create instances of the derived class? Ideally I would like the equivalent of a c++ typedef and I don't want the below syntax (which does work). BClass<int> d = DClass.Create();

    Read the article

  • Combine Lists with Same Heads in a 2D List (OCaml)

    - by Atticus
    Hi guys, I'm working with a list of lists in OCaml, and I'm trying to write a function that combines all of the lists that share the same head. This is what I have so far, and I make use of the List.hd built-in function, but not surprisingly, I'm getting the failure "hd" error: let rec combineSameHead list nlist = match list with | [] -> []@nlist | h::t -> if List.hd h = List.hd (List.hd t) then combineSameHead t nlist@uniq(h@(List.hd t)) else combineSameHead t nlist@h;; So for example, if I have this list: [[Sentence; Quiet]; [Sentence; Grunt]; [Sentence; Shout]] I want to combine it into: [[Sentence; Quiet; Grunt; Shout]] The function uniq I wrote just removes all duplicates within a list. Please let me know how I would go about completing this. Thanks in advance!

    Read the article

  • Generic <T> how cast ?

    - by Kris-I
    Hi, I have a "Product" base class, some other classes "ProductBookDetail","ProductDVDDetail" inherit from this class. I use a ProductService class to make operation on these classes. But, I have to do some check depending of the type (ISBN for Book, languages for DVD). I'd like to know the best way to cast "productDetail" value, I receive in SaveOrupdate. I tried GetType() and cast with (ProductBookDetail)productDetail but that's not work. Thanks, var productDetail = new ProductDetailBook() { .... }; var service = IoC.Resolve<IProductServiceGeneric<ProductDetailBook>>(); service.SaveOrUpdate(productDetail); var productDetail = new ProductDetailDVD() { .... }; var service = IoC.Resolve<IProductServiceGeneric<ProductDetailDVD>>(); service.SaveOrUpdate(productDetail); public class ProductServiceGeneric<T> : IProductServiceGeneric<T> { private readonly ISession _session; private readonly IProductRepoGeneric<T> _repo; public ProductServiceGeneric() { _session = UnitOfWork.CurrentSession; _repo = IoC.Resolve<IProductRepoGeneric<T>>(); } public void SaveOrUpdate(T productDetail) { using (ITransaction tx = _session.BeginTransaction()) { //here i'd like ot know the type and access properties depending of the class _repo.SaveOrUpdate(productDetail); tx.Commit(); } } }

    Read the article

  • Generic JSON parser in .NET / WPF?

    - by niklassaers
    I've read lots of tutorials on how to deserialize a JSON object to an object of a particular using DataContractJsonSerializer. However, I'd like to deserialize my object to a Dictionary consisting of either Strings, Arrays or Dictionaries, such as System.Json does with SilverLight when I say JsonObject.Parse(myJSONstring). Is there an equivalent to System.Json that I can use in my WPF project? (just a short background: I'm fetching JSON objects that have way to much info, and I just want to use a little bit to fill out a String array) Cheers Nik

    Read the article

  • A good Sorted List for Java

    - by Phuong Nguyen de ManCity fan
    I'm looking for a good sorted list for java. Googling around give me some hints about using TreeSet/TreeMap. But these components is lack of one thing: random access to an element in the set. For example, I want to access nth element in the sorted set, but with TreeSet, I must iterate over other n-1 elements before I can get there. It would be a waste since I would have upto several thousands elements in my Set. Basically, I'm looking for some thing similar to a sorted list in .NET, with ability to add element fast, remove element fast, and have random access to any element in the list. Has this kind of sorted list implemented somewhere? Thanks.

    Read the article

  • LINQ Equivalent query

    - by GilliVilla
    I have a List<string> List<string> students; students.Add("123Rob"); students.Add("234Schulz"); and a Dictionary<string,string> Dictionary<string, string> courses = new Dictionary<string, string>(); courses .Add("Rob", "Chemistry"); courses .Add("Bob", "Math"); courses .Add("Holly", "Physics"); courses .Add("Schulz", "Botany"); My objective now is to get a List with the values - {Chemistry,Botany} . In other words, I am trying to get the LINQ equivalent of select value from [courses] where [courses].key in ( select [courses].key from courses,students where [students].id LIKE '%courses.key%' ) How should the LINQ query be framed?

    Read the article

  • Creating a Type object corresponding to a generic type

    - by Alexey Romanov
    In Java, how can I construct a Type object for Map<String, String>? System.out.println(Map<String, String>.class); doesn't compile. One workaround I can think of is private Map<String, String> dummy() { throw new Error(); } Type mapStringString = Class.forName("ThisClass").getMethod("dummy", null).getGenericReturnType(); Is this the correct way?

    Read the article

  • Scala 2.8.1 implicitly convert to java.util.List<java.util.Map<String, Object>>

    - by Ralph
    I have a Scala data structure created with the following: List(Map[String, Anyref]("a" -> someFoo, "b" -> someBar)) I would like to implicitly convert it (using scala.collection.JavaConversions or scala.collection.JavaConverters) to a java.util.List<java.util.Map<String, Object>> to be passed the a Java method that expects the latter. Is this possible? I have already created the following method that does it, but was wondering if it can be done automatically by the compiler? import scala.collection.JavaConversions._ def convertToJava(listOfMaps: List[Map[String, AnyRef]]): java.util.List[java.util.Map[String, Object]] = { asJavaList(listOfMaps.map(asJavaMap(_))) }

    Read the article

  • Binding to a List<object> in silverlight problem.

    - by cw
    Hello, Can someone suggest what I am doing wrong? Basically I have a List Items, when an item gets added to the list I am resetting the collection to the viewmodel property. The only way I can get it to work is if I null the member object out before reassigning the binding. Any suggestions on how to go about updating a UI when an item gets added to a List? public List<Item> RegisteredItems { get { return m_vRegisteredItems; } set { m_vRegisteredItems= null; NotifyPropertyChanged("RegisteredItems"); m_vRegisteredItems= value; NotifyPropertyChanged("RegisteredItems"); } }

    Read the article

  • Generic calls to OnResetDevice() and OnLostDevice()

    - by bobobobo
    This is kind of a COM question to do with DirectX. So, both ID3DXSprite and ID3DXFont and a bunch of the other ID3DX* objects require you to call OnLostDevice() when the d3d device is lost AND OnResetDevice() when the device is reset. What I want to do is maintain an array of all ID3DX* objects and simply call OnResetDevice() and OnLostDevice() on each whenever the device is lost or reset. However I can't seem to find a BASE CLASS for the ID3DX* classes... they all seem to COM-ually inherit from IUnknown. Is there a way to do this or do I have to maintain separate arrays of ID3DXFont* pointers, ID3DXSprite* pointers, etc?

    Read the article

  • Algorithm to suggest a list of tags to users

    - by Itay Moav
    Given a free text, I need to analyse this this text and suggest a list of tags from a pre existing list. What algorithms are out there in the market? Can they handle a case where, for example, the text have a word like high cholesterol and I would like it so suggest heart disease although "high cholesterol" might not exists (initially) in the pre defined list.

    Read the article

  • Default for generic type?

    - by Mark
    Is it possible to do something like public class PriorityQueue<TValue, TPriority=int> where TPriority : IComparable (note the =int) ? Before you suggest it, yes, I know I can just add another line: public class PriorityQueue<TValue> : PriorityQueue<TValue, int> { } But I'm wondering if it's possible to do it as a param.

    Read the article

  • In JSF, how to handle repeating over a list that mutates

    - by Jon
    Hello, In a JSF page, I am iterating over a list of items provided by a session-scoped backing bean. The list needs to be kept up-to-date, so it is replaced with a fresh list every X minutes by a thread (in a thread-safe way). On my page, for each item I provide some text inputs and an "Update" button. If the list is refreshed before I hit "Update", the update does not happen (which is my problem). I happen to be using a4j:repeat, but I think this could also apply to other methods of iteration, including using dataTables. Any thoughts on how I can do this in a non-hackish way? Thanks!

    Read the article

  • How to add separator between items in a Spark List control

    - by simms2k
    I have a s:List where I've defined my own itemRenderer, and would like to insert a horizontal line separating items, similar to the way the mx:LinkBar works. I don't want to have a line at the top or bottom of the list, so I can't just include an upper or lower border in the itemRenderer. I was hoping the itemRenderer could be made aware of its index in the list, but I don't see how. Is there a way to do this?

    Read the article

  • Merge two lists of objects which hold different data

    - by C.McAtackney
    I have an object "Project" which has a number of fields, one of which is "Name". I have one spreadsheet of projects which contains some of these fields, and another which contains the rest. However, Both spreadsheets have the "Name" field. I've read them in and populated two List, only populating the available fields from that particular source. E.g. a Project from List 1 looks like; {Name="MyProj", Type="Form", Priority=NULL}, whereas a Project from List 2 {Name="MyProj", Type=NULL, Priority="High"}. Now, I want to merge these two lists into one in which each Project object has all of its fields populated, with the Name field being used to match the elements. How can I achieve this? Are there any nice ways of doing this concisely? Thanks

    Read the article

  • print friendly version of floated list

    - by Brad
    I have a list of phone extensions that I want to print a friendly version of it. I have a print css for it to print appropriately onto paper, the extensions are located within an unordered list, which are floated to the left. <ul> <li>Larry Hughes <span class="ext">8291</span></li> <li>Chuck Davis <span class="ext">3141</span></li> <li>Kevin Skillis <span class="ext">5115</span></li> </ul> I float it left, and when it prints the second page, it leaves off the name part of the list (in Firefox, works fine in Google Chrome and IE), see here: http://cl.ly/de965aea63f66c13ba32 I am referring to this: http://www.alistapart.com/articles/goingtoprint/ - they mentioned something about applying a float:none; to the content part of the page. If I do that, how should I go about making the list show up in 4 columns? It is a dynamic list, pulled from a database. Any help is appreciated.

    Read the article

  • C# Generic method type argument inference

    - by CaptainCasey
    Is there any way that I can generalise the type definitions here? Ideally, I'd like to be able to change the type of 'testInput' and have test correctly infer the type at compile time. public static void Run() { var testInput = 3; var test = ((Func<int, int>) Identity).Compose<int,int,int>(n => n)(testInput); Console.WriteLine(test); } public static Func<T, V> Compose<T, U, V>(this Func<U, V> f, Func<T, U> g) { return x => f(g(x)); } public static T Identity<T> (this T value) { return value; }

    Read the article

  • Java generic return tpye

    - by Colby77
    Hi, I'd like to write a method that can accept a type param (or whatever the method can figure out the type from) and return a value of this type so I don't have to cast the return type. Here is a method: public Object doIt(Object param){ if(param instanceof String){ return "string"; }else if(param instanceof Integer){ return 1; }else{ return null; } } When I call this method, and pass in it a String, even if I know the return type will be a String I have to cast the return Object. This is similar to the int param. How shall I write this method to accept a type param, and return this type?

    Read the article

  • Removing items from lists and all references to them.

    - by LiamV
    I'm facing a situation where I have dependent objects and I would like to be able to remove an object and all references to it. Say I have an object structure like the code below, with a Branch type which references two Nodes. public class Node { // Has Some Data! } public class Branch { // Contains references to Nodes public Node NodeA public Node NodeB } public class Graph { public List<Node> Nodes; public List<Branch> Branches; } If I remove a Node from the Nodes list in the Graph class, it is still possible that one or more Branch objects still contains a reference to the removed Node, thus retaining it in memory, whereas really what I would quite like would be to set any references to the removed Node to null and let the garbage collection kick in. Other than enumerating through each Branch and checking each Node reference sequentially, are there any smart ideas on how I remove references to the Node in each Branch instance AND indeed any other class which reference the removed Node?

    Read the article

  • ToList()-- Does it Create a New List?

    - by Ngu Soon Hui
    Let's say I have a class public class MyObject { public int SimpleInt{get;set;} } And I have a List<MyObject>, and I ToList() it and then change one of the SimpleInt, will my change be propagated back to the original list. In other words, what would be the output of the following method? public void RunChangeList() { var objs = new List<MyObject>(){new MyObject(){SimpleInt=0}}; var whatInt = ChangeToList(objs ); } public int ChangeToList(List<MyObject> objects) { var objectList = objects.ToList(); objectList[0].SimpleInt=5; return objects[0].SimpleInt; } Why? P/S: I'm sorry if it seems obvious to find out. But I don't have compiler with me now...

    Read the article

  • Generic Open Source REST Client?

    - by Dean J
    I want a simple client that takes a few parameters (Method, URL, Parameters), makes an HTTP request, and shows me the results that were returned. A browser obviously can easily send GET and POST requests, but I have no good ideas on DELETE and UPDATE. Did I miss something in browser 101, or is there a common freeware tool to do this? I've seen other threads that give me Java APIs for a simple client, but that's not what I'm looking for.

    Read the article

  • Compiled query using list of class objects in C#

    - by Sukan
    Hello , Can somebody help me out in creating compiled queries where input is to be a list of class objects? I have seen examples where Func<DataContext, somematchobject, IQueryable<T>> is created and compiled. But can I do something like Func<List<T>, matchObject, T>, and compile it? Basically I want an object(T) meeting certain conditions (as in matchObject) to be returned from a list of objects(List<T>). Will CompiledQuery.Compile help me in this? Please help me experts!!

    Read the article

  • Is there a generic interface wrapper framework

    - by epitka
    Is there a framework or a native way in .net to dynamically generate wrappers for specified interface. I need a way to say, here is a type I have and here is the interface I want to wrap around it, and for each method it the interface forward calls to these methods on the type provided.

    Read the article

  • run a function when a user clicks on any list element

    - by sova
    This is probably a very common question, but I was unable to find an answer myself; All my list elements call the function setQuery like this onClick="admin_stats.setQuery(this);" rather than [hardcode] add this to every list element, is there a way to simply have it run when a list element is clicked? I'm not very familiar with jQuery Live or binding/unbinding, but I think they would play a role here? Before I reinvent a rather square-looking wheel I thought I might ask =)

    Read the article

  • Google MAP API v3: Link markers to an external list

    - by meo
    Given is a database with locations, we feed those tho the google map api and all points are displayed. Now there is a list of this location right next to the google map. How can i link the places in the list to the dots on the map? Like this: http://www.local.ch/en/q/ubs.html I want to light up the point on the map on the list item hover and open the info-box by clicking on the list item. Can anyone point me into the right direction?

    Read the article

< Previous Page | 91 92 93 94 95 96 97 98 99 100 101 102  | Next Page >