Difference Between Generic And Non - Generic Collection?
Oct 30, 2010What is the difference between generic and non-generic collection?
View 1 RepliesWhat is the difference between generic and non-generic collection?
View 1 RepliesWhen I dump the contents of a List<string>, I get:
Sue
Larry
John Barrowman
Bob
However, when I try to retrieve the index of the strings using this format...
thisIndex = blockRetrievedList.BinarySearch("Sue");
and print the indexes in an HTML list, here's the results that I get...
Using blockRetrievedList.BinarySearch('Larry'); : 1
Using blockRetrievedList.BinarySearch('Mike'); : -5
Using blockRetrievedList.BinarySearch('Sue'); : -5
Using blockRetrievedList.BinarySearch('Bob'); : -1
Using blockRetrievedList.BinarySearch('John Barrowman'); : -1
So while Larry comes out fine at index one, John Barrowman and Bob should be indexes 2 & 3 respectively. However, they're coming up -1 meaning they're not recognized as being the collection. Further Mike (who was originally in the set, but who has now been replaced by John Barrowman is coming up -5. Isn't that supposed to be -1? And why on Earth is Sue (who is index 0, returning -5 as well?
I have GridView bound to some List. In layout I created following template field:
<asp:TemplateField HeaderText="Phrase">
<ItemTemplate>
<asp:TextBox ID="phraseTextBox" runat="server" Text='<%# Bind("Phrase") %>'/>
</ItemTemplate>
</asp:TemplateField>
But after changing the content of any TextBox in column "Phrase" my List doesn't reflect that changes.
I was building an application for a project with .NET 3.5 and I noticed a weird behaviour of the List.Add method:
I have built my own class to organize data pulled from a database, and I use a while cycle to iterate through it.
However, when I List.Add(item), the whole content of the list is substituted with the last content pulled.
An example:
Suppose you have 3 users in a DB, each one identified with an ID and a username:
| ID | username |
| 1 | John |
| 2 | Fred |
| 3 | Paul |
and you have a "Users" class defined as
public class Users
{
private Int32 iD;
private String username;
public Int32 ID
{
get { return iD; }
set { iD = value; }
}
public String Username
{
get { return username; }
set { username = value; }
}
}
So you write this function:
[... SQL definitions - sdr is a SqlDataReader ...]
List<Users> userlist = new List<Users>();
if (sdr.HasRows) //There are users
{
Users user = new Users();
while (sdr.Read())
{
user.ID = sdr.GetInt32(0);
user.username = sdr.GetString(1);
userlist.Add(user);
}
}
What you expect (I expect) is userlist containing:
| ID | username |
| 1 | John |
| 2 | Fred |
| 3 | Paul |
What I actually get is, instead
| ID | username |
| 3 | Paul |
| 3 | Paul |
| 3 | Paul |
I'm receiving this error in my Linq statement ---
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'hcgames.ObjectClasses.ShoppingCart.ShoppingCartCartAddon'. An explicit conversion exists (are you missing a cast?)
From this query
ShoppingCartItems items = Cart.GetAllItems();
ShoppingCartCartAddons addons = Cart.GetAllAddons();
var stuff = from x in items
select new ShoppingCartItem()
{
ProductID = x.ProductID,
Quantity = x.Quantity,
Name = x.Name,
Price = x.Price,
Weight = x.Weight,
Addons = (from y in addons
where y.ShoppingCartItemID == x.ID
select y)
};
I need to cache System.Collection.Generic.List object with expiration time
var Root = from feed in feedhotel.Descendants(ota + "HotelContent")
where (feed.Attribute("HotelCode") != null)
select new xmlhotel()
{
};
return Root.ToList();
Is it possible to cache Root.ToList() for some time....
I need a list to export in excel and i need the following to achieve in the exported excell
- I need the header of the excel with font bold and size should be 14px of font.
- Other Cell try should be 12px of the font
- Right align the particular column in the excel
What's up with difference between generic handler (ashx) and window communication foundation (wcf)? What their purpose?
View 1 RepliesI'm trying to create a control out of a class I found, and one of the overridden functions is the following:
protected override void PerformDataBinding(IEnumerable data)
However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.
i want to check my collection so i can add a new customer as long as the username does not exist in the collection i do not want 2 customers to be able to have the same username.
i have been trying many different things to try to get this to work but i am not exactly sure what i should be doing I have a aspforum and collection C# class of the list.
here is some things that i have tried
CustomerExists() i also have a collection of List<Customers>
//HERE IS MY EXISTS METHOD
public static Boolean IfCustomerExists(string login) {
List<Customer> theGuy = Collections.Customers;
bool exist = false;
foreach (Customer customer in theGuy)
[Code]....
I have a list view control. Each row within it has a rowid and a textbox where a note(user enters relevant info to that particular record) is entered. On a paging event I store the rowID and the note text in a generic list for retrieval if the user pages back later on. Goal here is to keep the text the user has entered. (see the code below)This generic list does in fact get populated correctly when I go to the next page currently. I can see this in Visual Studio. So now, when the user goes back to the first page I want to run a test within my Listviews ItemDataBound event. I want to see if the row ID being tested is part of the generic list. If so, I then want to take the corresponding note that is also within the list and bind it to the text box. However, I don't know how to write the correct conditional for this and how to bind the textbox if the conditional evaluates to true.
View 1 RepliesI have two generic list with Hotel class object. Both List contains hotel ID. I want to retrieve common hotel id from both Hotel List and assign to new HotelList.I have done following code for that but any other sort way to implement this kind of functionality.
[Code]....
Note: I dont want to use Linq because I am working on framwork 2.0
What is a Generic Class Declaration? and when should it be used?
View 2 RepliesI need to get an image from a SQL Server as a byte[], and load it to a WebControl.Image. The only seemingly good way to do it that I found is to implement IHttpHandler and handle the request accordingly.But I'm stuck to using asp.net 1.1. Does it support ashx files?
View 1 RepliesThe default implementation is not very appropriate normally and I haven't seen so far a good implementation of a custom membership provider, probably because this is not possible.
View 1 RepliesI'm trying to render out some images on an aspx page. Error I'm getting in the code below is:
DataBinding: '_Default+ImageThing' does not contain a property with the name 'FileName'.
public class ImageThing
{
public string FileName;
}
private void DisplayThumbnailImages()
{
ImageThing imageThing1 = new ImageThing();
ImageThing imageThing2 = new ImageThing();
imageThing1.FileName = "asdf.jpg";
imageThing2.FileName = "aaa.jpg";
List<ImageThing> imagesToRender = new List<ImageThing>();
imagesToRender.Add(imageThing1);
imagesToRender.Add(imageThing2);
Repeater1.DataSource = imagesToRender;
Repeater1.DataBind();
}
here is the aspx:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "FileName")%>
</ItemTemplate>
</asp:Repeater>
What is the best way to implement a open/cross platform web service API to an existing .NET App? Not being a strictly .NET friendly API. It already has ASP.NET exposed web services, but need to be built into an generic API allowing inserts, updates and deletes and returning results based on user criteria in standard SOAP, JSON or other common formats, similar to Google's Data API's. Are there any frameworks designed for this or is it a build it from scratch project implementing each format/protocol manually?
View 3 RepliesQuestion: I want to call a generic function, defined as:
Public Shared Function DeserializeFromXML(Of T)(Optional ByRef strFileNameAndPath As String = Nothing) As T
Now when I call it, I wanted to do it with any of the variants below:
Dim x As New XMLserialization.cConfiguration
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of x)()
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(GetType(x))()
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of GetType(x))()
But it doesn't work. I find it very annoying and unreadable having to type
x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of XMLserialization.cConfiguration)()
Is there a way to call a generic function by getting the type from the instance ?
I Have a generic handler that's serving member logo images:
http://site.com/logo.ashx?memberid=123
Now, I want to use it by caling a url like:
http://site.com/logo/john.jpg
So I would create a route for that (pattern: "logo/{username}.jpg"). But, my problem is - how do I retrieve {username} when inside ProcessRequest() of my generic handler? It's not a page, so I can't get Page.RouteData.Values.
in my model there is a List.
public class InvoiceModel{
public int InvoiceID { get; set; }
public int Date { get; set; }[code]...
for create view i can use Html.TextBoxFor(m => m.InvoiceID) and for Date.but how can i fill List?and how can i use global for this list as Shopping cart?
Define Generic in one line / I know that List<string>, Stack<string>, Queue<string>, Dictionary<string,string> & linkedList<string> alls are generic but i want to know its one Line
View 3 RepliesCan any one can describe the main diffrence between the array and generic list.
View 6 RepliesI have one Hotel class that contains many properties. When I retrieve all hotels data from database, I store them in Generic List object.Now what I want that I have two properties called LowestPrice and HiestPrice. I want to get Minimum(LowestPrice) and Maximum(HiestPrice) from generic list directly.
Something like HotelList.Min();
Right now I have following logic implemented in my project, but I dont want to use foreach loop.
[Code]....
I have a list of Categories which I need to bind to a TreeView control in WPF and I can't find a working tutorial or get it working.My Category class consist of (ID, Title, ParentID). If the Category is a top level category the parentID is null.Can anyone sow me how to bind this to a treeview?
View 3 RepliesI'm having a couple basic generics problems. Basically, I'm trying to identify a piece of content by two indexes.
1) I need to store the content in the class, so I need to create a class variable, classTableCellContent, to store it in. Therefore I need to create one, requiring me to constrain the generic type "where ContentType : new()". However, when I attempt to consume this type with a string, e.g. TableCell<string>, it throws a compiler error "The type 'string' must have a public parameterless constructor in order to use it as a parameter blahblahblah..."
2) I need to accept input, so I have an add function. However, when I try to indicate that the third parameter is the same data type, i.e. ContentType, the compiler seems to believe that I'm creating a "new" data type with a poorly chosen name that hides the original data type declared in the class declaration. I'm sure this must be something stupid I'm missing. All I want to do is accept an input variable of the generic type in a function and store it in the class for later use.
Here's the code. I've even highlighted the two lines that seem to be throwing the errors.
Code:
[code]....