.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

IEnumerable.Except incorrectly removes duplicates

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
IEnumerable.Except is expected to receive a second IEnumerable with the elements to be removed from the first. But when the first collection contains duplicates, those are removed too, despite not being present on the second. Check in the following example that 2.3 appears twice on numbers1 but only once on the output. double[] numbers1 = { 2.0, 2.1, 2.2, 2.3, 2.3, 2.4, 2.5 }; double[] numbers2 = { 2.2 }; IEnumerable<double> onlyInFirstSet = numbers1.Except(numbers2); foreach (double number in onlyInFirstSet) Console.WriteLine(number); /* This code produces the following output: 2 2.1 2.3 2.4 2.5 */

View Complete Post

More Related Resource Links

Accordion Control Renders Content Incorrectly


Hey Guys i'm using an accordion control with one pane. In all browsers it renders and works fine - except IE8. in IE8, it looks fine at first, but after collapsing and reopening the pane the text in my pane appears garbled. When i zoom in, i can tell it's in the original font, but it's almost as if it's an image that's blow up too big...

Content Type Saved Incorrectly Using DataView


I have created a blank web part page and added a data view for my selected list in which I have enabled the insert/edit/delete options.  In that data view I have included the content type field (my list has 3 content types).  I am using JavaScript to set some fields defaults and to hide those fields, one being the content type field.  All seems to work correctly when submittin a new entry except that each item I save is always saved as the 1st content type.  I have tried inserting a new item without any JavaScript and have the same problem - no matter which content type I select from the drop-down list the item is always saved as the 1st content type.  Am I missing something here?  Surely I don't have to use the standard list form to insert new items into my list as I need to be able to control the user's interaction using the options available in the data view.

SharePoint Server 2007, SPD 2007, both SP2.

Thanks for any insight!

IE 8 displays Sharepoint 2007 pages incorrectly



I have installed Sharepoint 2007 on a Windows 2008 r2 x64 server. When I browse a Sharepoint site on the server with IE 8 I get the pages displayed incorrectly.

If I use IE 6 I get the pages correctly displayed. I tryed to change the compatability view settings with no success. I have tryied this on different computes with IE 8 with same result.

Any ideas?



How to union two queries without duplicates


I have a sql query that returns 4 columns
CustName CustId CustZip CustPhone

I have a second sql query that returns the following 5 columns

CustName CustId CustZip CustEmail CustAddress

Both queries, query different data tables in the database, but return columns that are common to

How do I union the two queries(Assuming a union is needed)

Which will result in no duplicates and an end result being the following output:

CustName CustId CustZip CustPhone CustEmail CustAddress


As you can see we want to not have duplicate values on output. So something like the following
is not acceptable:

Jeff Stamper  2222234  81224  498-300-2222
Jeff Stamper  2222234  81224  498-300-2222 js@jj.com 122 Mars Blvd
Karen Bops  3322234    81666  498-300-2222
Karen Bops  3322234    81666  498-300-2222 kb@lpo.com 322 Jamer Road

Serializing objects which implement IEnumerable<>

Hi, I'm trying for long time to serialize an object which contains an object which implements IEnumerable<>. The last object also contains an object which implements IEnumerable<>. The objects strucutre is as followed: [Serializable] public class A { public B _b {get; set; } } [Serializable] public class B : IEnumerable<C> { public List<C> c_items {get; set;} public void Add (C obj){} } [Serializable] public class C : IEnumerable<D> { public List<D> d_items {get; set;} public void Add (D obj){} } [Serializable] public class D { public int Key {get; set;} public int Value {get; set;} } In the code line: A obj = new A(); XmlSerializer serializer = new XmlSerializer(obj.GetType()); I'm getting the exception: unable to generate temporary class (result=1), error CS0030: Cannot convert type 'C' to type 'D'... When I remove the IEnumerable implementation from one of B or C, the serialization works. What as I getting wrong? Any help would be appreciated!

remove Duplicates

Hi, I am want to create a primamry key on column a in table FARA, I am receiving an error that I have duplicates in column a. I tried copying the table using : select distinct into table FARA-u from table FARA. thought this should remove duplicates but I am still getting same error when i try to set primamry key on column a. how can i remove those duplicates ( I wil need to remove the whole row that conatins duplicates on column a) Thanks!

Need sum only 1 row for hide duplicates rows in a GROUP in Reporting Services

In a report grouped by Collateral Name, I have the same Collateral Amount in multiple rows.  I clicked "hide duplicates" so it only displays once on the report, but it is summing row the Collateral Amount that is sum from a every row that hidden.  Is there a way in RS to only sum the displayed row (or the top row in a group)? As the sample, I had the data as below:  Collateral Name                     Collateral Amount            Outstanding         C-1                                                    100                            20         C-1                                                    100                            15         C-1                                                    100                            30 Now I can show like this with Hide Duplication properties,  Collateral Name                     Collateral Amount            Outstanding         C-1                                                    100                            20                                                                                                    15                                                                                                    30 -----------------------------------------------------------------------------------------                                                                 300                             65 -------------------------

IEnumerable instead of IList or Collection

hi,Just wondering and see what your opinions are.I usually pass around the layers either a Custom Collection<T> or a Custom ListBase<T>:IList ..I was now wandering if instead of return from a Data Access Layer or biz layer one of those is better to actually just return an IEnumerable<T>.Shall I drop returning all those LIst<T> Collection<T> and use IEnumerable<T> instead?Would that be more flexible?Thanks for any suggestionsThanks for your help

Negative values sums up incorrectly

Hello, I have calculated measure that removes negative values. Problem is the Total is summing up incorrectly. Here the script of the measure. Create Member currentcube.[Measure].[Amount2] as iif ([Measure].[Amount]>0, [Measure].[Amount], null)   Below is sample result. Customer        Amount      Amount2 A                    100            100 B                    -50             C                    100            100 D                    100            100 E                     100            100 TOTAL          &n

There is no ViewData item of type 'IEnumerable' that has the key 'Carrera'.

When running the HttpGet action, it works fine. But when I run the HttpPost action, I recieve the error in the title. Can anyone help me out? Is it because the HttpPost doesn't have a ViewData declared? Thanks for the help.[HttpGet] public ActionResult Crear() { CarreraRepository carreraRepository = new CarreraRepository(); var carreras = carreraRepository.FindAll().OrderBy(x => x.Nombre); var carrerasList = new SelectList(carreras, "ID", "Nombre"); ViewData["Carreras"] = carrerasList; Materia materia = new Materia(); return View(materia); } [HttpPost] public ActionResult Crear(Materia materia, FormCollection values) { if (ModelState.IsValid) { repo.Add(materia); repo.Save(); return RedirectToAction("Index"); } return View(materia); }

Ienumerable,ienumerator and iterator Interface in c#

how I used Ienumerable and ienumerator and itreator interface in c# with Wcf I want To used Through Class. I want To used Through C# Plz Give Me A good Example.   Thanks Neha    

FAST for Sharepoint duplicates components

Setting up FAST for Sharepoint it turns out two unclear functionalities. Both FAST Content and FAST Query SSAs have a own index. We have to define some Content sources on FAST Content, but what about The Content Sources of FAST Query SSA ? They have to be define and crawled or not ? In FAST Query menu we can find "Metadata Properties" link, in FAST Search Administration Page we have "Managed Properties" . These sets do not seem the same. Which one is used by Search Site ? I'm not be able to find anything on this searching online documentation.

Only a single enumeration is supported by this IEnumerable.

I've only seen a few other posts on the internet about this error message, and none of them seem to give an answer that's relevant to Silverlight asynchronous code. I have a data service operation, I call it from a Silverlight client. I know the service operation is returning the desired data, because I have tested the code in a synchronous aspx page load and browsed it with the debugger. However, whether I have the service operation method return an IQueryable or an IEnumerable, I can't iterate through the results in the Silverlight client code - I receive the error in the title of this post. I can't do a foreach, I can't do a for loop, I can't do a ToList, they all give that error. private void on_oppquery(IAsyncResult result) { /*Use dispatcher to ensure that the asynch call returns in the correct thread*/ Dispatcher.BeginInvoke(() => { IEnumerable<opportunity> response = null; try { /*Since this is the first page, we get back the query*/ var query = result.AsyncState as DataContext; /*Get the response of the query*/ response = query.EndExecute<opportunity>(result); /*Enumeration executes the query*/ //THIS BREAKS //response.ToList<opportunity>(); //THIS BREAKS //foreach (opportunity o

IEnumerable Type Casting

Hello Everyone,  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 Public Class CountryInfo Implements IEnumerable Property Name As String Property Code As String Public Sub New(ByVal code As String, ByVal name As String) _Code = code _Name = name End Sub Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator Return CType(Me, IEnumerator) End Function Public Class SearchResult Private ReadOnly _countries As List(Of CountryInfo) Private ReadOnly _query As String Friend Sub New(ByVal countries As List(Of CountryInfo), ByVal query As String) _countries = countries _query = query End Sub Public ReadOnly Property IsEmpty As Boolean Get Return _countries.Count = 0 End Get End Property Public ReadOnly Property Countries As List(Of CountryInfo) Get Return _countries End Get End Property Public Function Bui

TraceListenerCollection is cleared when looping over IEnumerable

I have the following code in a class in a WPF application: In the constructor: foreach( var traceSource in AvailableSources.ToArray() ) traceSource.Listeners.Add( _listener ); Trace.AutoFlush = true; The AvailableSources property: /// <summary> /// Gets the available sources. /// </summary> /// <value>The available sources.</value> public IEnumerable<TraceSource> AvailableSources { get { yield return TraceSources.Network; // app-specific tracesource yield return TraceSources.Persistence; // app-specific tracesource yield return TraceSources.Gui; // app-specific tracesource PresentationTraceSources.Refresh(); yield return PresentationTraceSources.DataBindingSource;  // WPF tracesource yield return PresentationTraceSources.RoutedEventSource;  // WPF tracesource } } If I doesn't use ToArray() on the property AvailableSources in the foreach loop, the Listeners collection will have zero listeners. If I step through the foreach loop, I will at the end (but before hitting the first line of code outside the loop) have 1 listener in each TraceSource' Listeners collection. When I hit the first line after the loop, I get Listeners.Count = 0 on each tracesource. I've used the immediate window in VS.Net to get the current count of the listeners collection and also verified that the hash code of each tracesource instance

Find Duplicates

Hey Guys,I have the following query:SELECT tmp_random.tempStr FROM tmp_random GROUP BY tmp_random.tempStr HAVING (COUNT(tmp_random.tempStr) > 1) This is working great but I have one nagging issue, for example this returned the string 'uepog' as being duplicated in my table.When doing a search for just this I found these {'uepog', 'uEpog'}Although this is correct as technically they are the same but I want it to only match exact duplicates including case.Can this be done? How ?Many thanks

C# RSS Group Pubdate, remove duplicates

Hello. I am wanting to use c# to grab an RSS feed.  Remove duplicate pubdates and then sort the content by date, displaying the data under the heading of the pudate. I have to say I am at a loss I would be grateful for any suggestions. 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend