Extending System.Collections.Generic.List(Of T)?
Jan 27, 2010imagine i want to add an extension method to System.Collections.Generic.List(Of T)
let's say i want to give it .GetUBound which returns Count-1
imagine i want to add an extension method to System.Collections.Generic.List(Of T)
let's say i want to give it .GetUBound which returns Count-1
I'm having a problem with this code in the highlighted line(*); getting the error in the heading.
Dim htmlarraylist As New List(Of iTextSharp.text.IElement)
htmlarraylist = *HTMLWorker.ParseToList(New StreamReader(tempFile), New StyleSheet())*
[Code].....
[code]...
What's really the point in using the former?It's hard to use linq if I used the former. I have to convert that to an array first which is difficult because there is no (asarray) function.I think I would change all of my code that's using System.
Collections.Specialized.StringCollection to System.Collections.Generic.List(Of String)
I have a lists of different custom classes and each must be sorted severals times before the algorithm is complete. For each sort I wrote a comparer. Sofar so good. Everything works. But: By now I have abou a dozen different comparers in more than one class and it is still getting more. I wonder if there is a way to limit the number by writing a new general function that can be used to sort all lists without the need for a specific comparer.Below is what I've got so far. But it does not work.
"System.Collections.Generic.List(Of ClassA)" can not be converted into "System.Collections.Generic.List(Of Object)."
[code].....
i have issue returning a list in a web method. here is the code
<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)()
Dim context As New PPEntities
[code]....
the error is
Value of type 'System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)'
I am trying to pass a System.Collections.Generic.List to another class. The collection is created in class2 and then passed into class1
[code]...
However I get a 'Null Reference Exception error' when I run the program. It seems f_str in the line 'For Each s As String In f_str' is null.
how to find a value in the System.Collections.Generic.List.I have:
Private ids As New List(Of Byte())
ids.add(New Byte(){&HA8,&H0F})
ids.add(New Byte(){&HFF,&H03})
ids.add(New Byte(){&H10,&H00})
I would like to find for example: &H10,&H00 in that list and if there isn't the stuff I wan't to find then how do I know that?
I need to be able to tell if a property is of type List(of T)but am currently unable to. if i do
TypeOf (UpdateTo.GetType.GetProperty(node.Name)) Is System.Collections.Generic.List(Of Object)
I get the following error
TypeOf (UpdateTo.GetType.GetProperty(node.Name)) Is
System.Collections.Generic.List(Of Object) Expression of type
'System.Reflection.PropertyInfo' can never be of type[code]......
in what situation will an item in System.Collections.Generic.List not be removed successfully?url...The way they phrase it makes me think that it is possible that a Remove operation on an item found in the List(Of T) could actually fail.
View 4 RepliesI need another (dozen) pair of eyes on this. The following code:
Interface iRuleEntity
Function GetRuleViolations() As List(Of RuleViolation)
End Interface
Partial Public Class Feedback
[code]....
is giving me this error:'Feedback' must implement 'Function GetRuleViolations() As System.Collections.Generic.List(Of RuleViolation)' for interface 'iRuleEntity'.
I'm getting an error after sending a list to a web service.This is the code that is calling the web service:
Dim sProgramInterest As New List(Of Integer)
crmService.InsertProspectGetId(sProgramInterest.ToList)
But I'm getting this error.
[code].....
I have converted c# .cs to vb:= I have 6 errors on:
Red "List" says Too few type arguments to system.Collections.Generic.List(Of T)'
Orange "Calendar" says Value of type 'System.Windows.Forms.Control.ControlCollection' cannot be converted to 'Form1.Kobush.Windows.Forms.Appointment'.
[code]....
If i wish to put items into a System.Collections.Generic.Dictionary, I can either Add or set the Item.I know if you do Add it helps you check if the key already exists and if not it throws an exception.Now I'm curious, so if I'm adding a ton of items, should I prefer setting Item instead of Add since Add does unnecessary checks that may actually slow things down?
View 3 RepliesI am planning to use a List in my application but when I was searching for System.Collections.Generic, it only has System.Collections. I tried to look it up in the "add reference" and its not there.
View 2 RepliesThis code:
vb Dim s As String = strContents '<a global variable) Dim currentPos As Int64 = 0 Dim endPos As Int64 = strContents.Length - 1 '// A dictionary, used to count the frequencies Dim characterCounter As New Dictionary(Of [String], Int64)() While currentPos <> endPos '//
[CODE]...
Gives this error: Value of type 'System.Collections.Generic.KeyValuePair(Of String, Long)' cannot be converted to 'System.Collections.DictionaryEntry'.
I have an class named Foo. This class contains a collection of child objects of type FooChildBase, but I also have a further class of type FooChildTwo which inherits from FooChildBase.
Class Foo
Public Children As IList(Of FooChildBase)
End Class
Class FooChildBase
[code]....
What I would like to do is have my FooSpecial Class treat it's Children collection as if they were FooChildSpecial objects, but still be able to add FooChildTwo objects to it. Is this possible and if so how can it be done?
EDIT:I need to FooChildSpecial class to wrap any of the objects in the Children collection with the extra values, whether they are FooChildBase or FooChildTwo?
We have migrated our Vb6 application to VB.NET using a third party tool. Now we are in a process of Refactoring and introducing object oriented concepts in the application.
In VB6, we were using structures in many places. As a part of introducing object oriented programming,
1. is it a good idea of changing all Structures to Classes? or Is there a concept of "Generic Structure" similar to Generic collections, Generic classes?
2. Can some one guide me any source containing guide lines or best practices for applications that are migrated to VB.NET from VB6 and implementing object oriented programmaing.
I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expressions and the ToDictionary Method, I am getting the following error:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Int32,System.String]' to type 'MyDictionary'. I have simplified the example and recreated it in LINQPad and am getting the same error.
Here's the simplified version of my code:
[Code]...
And here is the code that produces the error
CODE:
How can i cast this one?
I have a parent class and many children class, right now it look like this:
Public Class Parent
Public Property ID as String
End Class
[Code].....
What I need is a strongly type list List(Of Child) that Inherits from ListOfParent (I need the FindByID method) but I can't find the right syntax.
Is there an exhaustive list of all of the "base" (not used in an object-oriented sense but more in a common sense) generic types in the 4.0 .NET Framework? I have found this list that I often send newer/mid-level devs to so they can understand how non-generic types map to generic types, but this is by no means exhaustive. I'm looking for something that also includes things such as KeyValuePair<>, Tuple<>, and other basic generics that may not be very-well known. Interfaces such as IObservable<> would be nice but not necessarily required.
View 6 RepliesI've hit a problem with the way I am using generics and I suspect that my design isn't quite right. I have a base class
AbstractBaseClass
inherited by
InheritingOneClass
[code]....
I have a generic list IList(of T as AbstractBaseClass) which I am populating with instances of the various inheriting classes. Now I can cycle through the list BUT depending on which subtype the item is, I want to pass the item to various functions (or instantiate various classes) which access properties/methods of the inheriting Class. I don't really want to have to use a Select Case and list all the potential types of the Inheriting classes. Is there a mechanism I can put in place to automate this?
I am new to VB.NET, just landed a job fresh out of school (well still in school), but I am having trouble with VB...alot of it is getting used to the IDE itsself (we use VB 2010).t does alot of the work for you which is cool but I am having some trouble understanding some concepts.Here are my questions: How to call classes named an initialized on a DSS skeleton to a new page. And the functionalities of building a collection. (also the differences of a generic
View 5 Repliesgiven the following class structures:[code]I add the following property to MyList, trying to answer questions like "find out the number of elements with specified type, say Derived1, inside MyList?"[code]
View 1 RepliesI want to write a generic file saving routine where the routine is passed data in the form of a collection and it sets a containsStructure flag. I wanted to be able to save the data from the collection, but if it is a collection of structures I want to be able to extract the data from the structure to write to the file.
The only trouble is, that I cannot do something like:
For Each s As dataStructure In data
Next
Since the compiler complains that dataStructure is not defined. Is there a way to code around this?
I am using Visual Studio 2005 and am writing a SSIS package. In the package I have a VB.Script that looks at a directory on a server and creates a list of the files. I then have a store Proc that looks at a table and gets a list of files that matches the files in the first array. The result is a fullresultset. The next step I need to create a 3rd array that only contains the rows from the first that are not in the second. However, I am getting the following error. Error: The script threw an exception: Unable to cast object of type 'System.Object' to type 'System.Collections.ArrayList'.
View 3 RepliesI recently discovered that the standard System.Boolean value is actually 32 bits - this seems pretty "far out there" since it's only ever going to be 1 or 0 - I found this information in somebody's blog which contained 3rd-party documentation on the System.Collections.BitArray. According to this blog, the individual Boolean is 32 bits while the individual index entry in a BitArray is actually just 1 bit - official documentation here at
MSDN indicates that in reality, the BitArray is just an array of Boolean Values (which would be the same size as any other boolean) that provides methods and functions useful in deconstructing System.Byte values into the BitArray and reconstructing the BitArray back into a System.Byte (same with System.Byte()).
I'd rather not go through a lot of code to restructure Boolean Arrays into BitArrays unless there's going to be some genuine memory-use improvement (which I'd expect to see if I converted large Boolean arrays - at 32 bits per index - into large BitArrays at 1 bit per index). I'm also interested to know if the Boolean is actually a 32 bit monstrosity.
This is the following. Normally, when i have a city, i'm using some javascript to autocomplete the cities as the user type. Now i want it to make it automaticly, using the edittemplate. So i would change :
[Code]...
I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:
Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName
[Code]....
The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.
Im working on my first n-tier application. I am trying to serialize a structure and Im getting an error"Soap Serializer does not support serializing Generic Types : System.Nullable`1[System.DateTime]."Here is the structure that is being serialized
Namespace Structures
<Serializable()> _
Public Structure structAllergy
Public AllergyID As String
Public ProfileID As String
[code]....
The bold line is the line that is throwing the error.