C# - Arrays - Use The IEnumerable<T> Interface And Make It Type Specific
Mar 1, 2011
In many projects I work on, whenever I have to return a read only collection, I use the IEnumerable<T> interface and make it type specific like so:
CODE:
Most of the time, I return a List but in some functions and read only properties I return an array which also serves the purpose alright by kind courtesy of Extension Methods.
My question is am I violating any design principles by returning IEnumerable<T>s instead of specific types (e.g.: List<T>, HashSet<T>, Stack<T> or Arrays)?
View 8 Replies
ADVERTISEMENT
Jan 13, 2011
While learning to use LINQ in VB.NET, I came across the following:Dim x As IEnumerable = (some LINQ query)
If you can't instantiate an interface, but only a concrete implementation of it, why is this allowed? Is there some difference between doing Dim x as (Type) and Dim x as New (Type)?
View 1 Replies
May 25, 2009
is there a way to retrieve type T from IEnumerable<T> through reflection?
e.g.
i have a variable IEnumerable<Child> info; i want to retrieve Child's type through reflection
View 6 Replies
Jan 7, 2012
And here is the code that produces the error
CODE:
How can i cast this one?
View 1 Replies
Sep 10, 2010
The following line is giving me an InvalidCastException when trying to convert to IEnumerable type, even though I have implemented IEnumerable interface. Return New CountryInfo(CountryCodes(i), CountryNames(i)) (also in bold below)
Imports System
Imports Gaia.WebWidgets.HtmlFormatting
Imports System.Collections.Generic
Imports System.Globalization
[code]....
View 1 Replies
May 9, 2011
I have an object called Result<T> that has a constructor which accepts an argument of IEnumerable<T>. I'd like to be able to pass in a datatable if possible.
I tried datatable.AsEnumerable(), but where I bind to the data it was complaining that 'MyProperty' is not a field or property on type 'DataRow' - which makes sense since 'MyProperty' isn't a property on 'DataRow', but it was a column in my datatable.Is there a way to convert a datatable to something that I can pass into the Result object and still have it bind to, say, a gridview?
View 3 Replies
Feb 28, 2012
I am creating a gridview and need to gather the data from various functions that return a type of IEnumerable. I've created gridviews using a dataset as a datasource, but how does one use multiple data sources(of IEnumerable) to populate one gridview? Like how do you combine all that into one dataset?
View 1 Replies
Dec 16, 2010
I tried using the linq Zip method on IEnumerable but it does not work for more than 2 arrays.Here is an example in Python of what I am trying to do(I got p - nested IEnumerable - and need q - another nested IEnumerable):
>>> l=['a','b','c']
>>> m=[1,2,3]
>>> n=['x','y','z'][code].......
View 2 Replies
Jun 1, 2012
I am building a software which will be used to create a remote desktop connection. However I'm getting this error:
Unable to cast COM object of type 'System.__ComObject' to interface type 'MSTSCLib.IMsTscNonScriptable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C1E6743A-41C1-4A74-832A-0DD06C1C7A0E}' failed
due to the following error: Δεν υποστηρίζεται τέτοια διασύνδεση (Exception from HRESULT: 0x80004002 E_NOINTERFACE)).
[Code]...
View 1 Replies
Feb 14, 2012
In trying to add a bit of usage variety to a generic class I'm working on, I ran into this issue with trying to cast an object into an interface instance where the interface is defined inside the generic class.
[Code]...
View 1 Replies
May 10, 2009
I have been trying to use vb2008 to automatically update CustomDocumentProperties fields that I have set up within a pro-forma document. I can load the Word application and word document without problems.I want to update the CustomDocumentProperties fields with data read from a dB. To do this I am assuming that I need to iterate through the CustomDocumentProperties fields within the word document and when one is "found" that matches the data I wish to merge then assign the dB value to the field.The problem is that I am getting an exception error when I try to reference the document customdocumentproperties
"Error : Unable to cast the COM object of type 'System._ComObject' to interface type 'Microsoft.Office.Interop.Word.CustomProperties'. ...... "
my code looks like;
Dim WordApp As Word._Application
Dim odoc As Word._Document
Dim BContinue As Boolean = True
[code].....
View 2 Replies
Apr 27, 2010
Strange story... I downloaded VMWare but it has since advised of an available update. I downloaded the update and when I click to install it, a window comes up with VB Code from a project I created a while back in a completely separate folder from this install file. I then tried downloading the trial of VMWare Workstation and when running the installer it shows the same thing. I don't know of anyway to contact VMWare support since I don't pay for any services or products and all there is available is a FAQ type section. Of course this problem would not be in there, nor can I find any such related issue online. his is VMWare specific or perhaps the type of install specific. I have no other issues with any other app installations other than with VMWare installations.
View 2 Replies
Apr 12, 2010
being used to PHP and the easiness of creating arrays with no specific size... I'm hating arrays in VB.
Is there a way I can create an array who's size I won't know?
I'm pulling information out of an XML file and need the information available in another sub - so I'm stashing it in a public array I create at the beginning of the form.
[Code]...
View 4 Replies
Jan 8, 2009
I'm trying to find out a way to search multiple arrays for a specific value. I looked through here, yahoo, google and msdn and couldn't find anything specific to what I'm looking for. Don't have any sample code as I'm not quite sure where to start.
View 2 Replies
May 1, 2010
1. When I try to do something like; Imports System.Collections
[Code]...
View 9 Replies
Jun 16, 2009
I am very close to cracking a problem I've had in visual basic 2008 that i am running out of visual studio 2008. I would like to generate a graph on a form using MSChart. I have got the first bit sorted out ie i can get a graph to show on a form using the following code (I've only put the first tranche in for the purpose of this question:[code] I can't get the array or string to be compatible with the one dimensional, comma-delimited array that I need to populate the y-axis values of the chart.
View 9 Replies
Feb 3, 2011
In some DLL, I have an interface defined like this (shortened code):
Public Interface wsIInvoice
''' <summary>
''' Perform plugin specific actions for a given memberhip invoice that is processedin an incasso batch, and return success result.
[Code].....
The DLL implementing the interface has a reference to the one defining it. And the defining DLL is imported.
I'm doing exactly the same thing in another DLL, and there VS does not complain.
View 2 Replies
Oct 20, 2008
I need to display a list with 2 columns and "n" rows (first column will be an IP address and second column the status - say connected, failed, etc).The case is that I need to be able to SET and GET the value of a certain cell. For instances, if the user click the first row of the list (row 0), I want to be able to get what is the intersection 0,0 (IP of first row) and intersection 1,0 (status of first row) and so on.I am trying Listview and Datagridview with no success.
View 8 Replies
Dec 9, 2010
I want to rotate a graphic at a point and I used the centerX and centerY to define the center of rotation.
Here is what I wrote:
Dim rotate_mirror as new RotateTransform(CSng(txtbx_rotate_by.text))
rotate_mirror.centerX = 5
rotate_mirror.centery = 55
blk_mirror.RenderTransform = rotate_mirror
blk_mirror is the graphic I want to rotate. Unfortunately, It does not work.
View 6 Replies
Mar 2, 2010
Ever since I started using VB.Net I have been using the Generic List collection List(Of <Type>). Arrays, I haven't used so much. I used them a lot more when I wrote C code years ago.
1.) Are arrays considered a type of collection like Lists, Dictionary, Queue etc are? Or are they in their own category.
2.) Can I iterate over an array with a For Each loop like I can with other collections or do I stick with the normal For loop for arrays?
3.) There are certain methods that return arrays. Can I set a list object to hold this return value instead of an array?
View 6 Replies
Mar 4, 2010
I have a database table of company information.It's about 50 records and contains things like company id, company name, address, phone number, shipping rate1, shipping rate2,etc.I want to load that table into a structure that I can quickly search within my code.I want to search by id to find the company, and then use the company's data to update some records.My lazy way has always been to add a listbox for each piece of data, then do an indexof on the id, then access the same index on the other listboxes.[code]
View 6 Replies
Jan 6, 2012
I am trying to implement the Strategy design pattern using interfaces.However, while developing some code I stumbled upon something strange.The type of the object is not verified in design-time.Observe the following code.Notice that Foo implements IFoo and Bar DOES NOT implement this interface.No error is shown when trying this:[code]This code compiles fine. No error is shown in Visual Studio.However, when I run this piece of code, I receive an InvalidCastException.The output of the console:[code]
View 1 Replies
Oct 25, 2010
I need to know if a Type implements an interface. [Code] because the Interface IRule itself is assignable of IRule what raises a MissingMethodExcpetion if i try to create an instance:
ruleObj = CType(Activator.CreateInstance(typeAsm, True), Rule.IRule)
UPDATE2: IsAssignableFrom in combination with IsAbstract might be the best way to check if a given type implements an interface and is not the interface itself (what throws a MissingMethodException if you try to create an instance).
If GetType(Rule.IRule).IsAssignableFrom(typeAsm) AndAlso Not typeAsm.IsAbstract Then
View 5 Replies
May 20, 2009
I am working on a project that has several different codes. These codes all basically are used this way:
CodeKey
Description
GetList
GetSpecific
SetProperties
All of my classes implement this. I am hesitent, however, to use an interface because of one problem--the type Codes vary by type. Some are strings, some are integers, some are bytes. The only way I could see using an interface would be to make the typeCode an object in the interface and then cast whenever I needed to use it, but that seems a bit silly. Any ideas? This is in VB.NET.
View 1 Replies
Nov 22, 2011
I am looking to implement the ability to compare and sort classes in my model. All of the objects in my model will need some common functionality regarding to comparisons so I created an abstract BaseComparer that implements IComparer.
Public MustInherit Class BaseComparer(Of T)
Implements IComparer(Of T)
End Class
[code].....
View 2 Replies
Feb 12, 2009
I would like to check if a property's type is an interface (not a specific interface, but any interface).
dim __PropertyInfo As PropertyInfo
dim b as boolean = isinterface(__PropertyInfo)
[code].....
View 3 Replies
Mar 1, 2010
I'm currently trying to create a class that is a composition of the SqlDataAdapter class (as unfortunately you can't inherit from it). In order to try and make it as similar as possible I'm using all the same inherits and interfaces as is documented on MSDN.The problem that I am having is that there are some properties where the interface specifies that the type of the property is IDbCommand. But in the SqlDataAdapter the property type is SqlCommand.
View 3 Replies
Dec 10, 2010
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding Path={x:Static vmc:clsPersonViewModel.ChildrenPath}, Mode=OneWay}">
<ItemsControl.ItemTemplate>
[Code].....
In the code above, if there are no children (the ChildrenPath property returns NULL), nothing is rendered in the view. In the code below, when ChildrenDataSetPath is NULL the XamDataGrid still gets rendered. How do I achieve the same for a single object (as opposed to a collection) as the datacontext?
<DataTemplate DataType="{x:Type vmb:clsPersonViewModel}">
<igDP:XamDataGrid DataSource="{Binding Path={x:Static vmb:clsPersonViewModel.ChildrenDataSetPath}}">
[Code].....
View 2 Replies
Oct 19, 2010
what is the difference between declaring a variable in this way
ByVal
List As IEnumerable as
a parametre in a function
Dim
[Code]....
View 1 Replies
Dec 27, 2010
I would like to have a command prompt type interface on my form. The only thing I am aware of is a textbox, but there are no facilities to have commands and output scroll without keeping the entire history in a variable. That would be an ever increasing variable, which is ridiculous. Is there an alternate way to use a textbox as a command prompt, or is there something else I can do. Another note, is the use of an array. I know I can increase an array with commands, but this is no good either, because some responses in the box need to be paragraphs in length, so even a separate array for command and output is too cumbersome.
View 6 Replies