Click here to Skip to main content
15,902,189 members
Home / Discussions / C#
   

C#

 
AnswerRe: Windows Form Pin
Dave Kreskowiak10-Nov-08 3:46
mveDave Kreskowiak10-Nov-08 3:46 
QuestionShared Document Pin
Sperneder Patrick9-Nov-08 22:54
professionalSperneder Patrick9-Nov-08 22:54 
AnswerRe: Shared Document Pin
Simon P Stevens9-Nov-08 23:42
Simon P Stevens9-Nov-08 23:42 
AnswerRe: Shared Document Pin
Brij10-Nov-08 0:04
mentorBrij10-Nov-08 0:04 
QuestionDistinct LINQ questions Pin
Programm3r9-Nov-08 22:49
Programm3r9-Nov-08 22:49 
AnswerRe: Distinct LINQ questions Pin
Guffa9-Nov-08 23:27
Guffa9-Nov-08 23:27 
GeneralRe: Distinct LINQ questions Pin
Programm3r10-Nov-08 0:00
Programm3r10-Nov-08 0:00 
AnswerRe: Distinct LINQ questions Pin
Simon P Stevens9-Nov-08 23:36
Simon P Stevens9-Nov-08 23:36 
You can't just use distinct when there is more to what you are getting that just the part you want to be distinct.

You need to use the override of distinct that takes an equality comparer. Then in the comparer, you can provide an implementation of how to determine if the data is distinct or not.

However, you can't do this with anonymous types.

One way of doing it would be like this:
class Program
{
    static void Main(string[] args)
    {
        String[] files = Directory.GetFiles(@"C:\My Files");
        var distinctFiles = files.Distinct(new FileEqualityComparer());

        foreach (var file in distinctFiles)
        {
            Console.WriteLine(file);
        }

        Console.ReadLine();

    }
}

public class FileEqualityComparer : EqualityComparer<string>
{
    public override bool Equals(string x, string y)
    {
        String FileNameX = x.Split(new Char[] { '_' })[1];
        String FileNameY = y.Split(new Char[] { '_' })[1];

        return FileNameX == FileNameY;
    }

    public override int GetHashCode(string obj)
    {
        String fileName = obj.Split(new Char[] { '_' })[1];
        return fileName.GetHashCode();
    }
}</string>
But that's not great because it will be doing the split code for every comparisom. A better way to do it would be to define a new class or struct to hold your 'file' data.

Simon

GeneralRe: Distinct LINQ questions Pin
Programm3r10-Nov-08 0:12
Programm3r10-Nov-08 0:12 
Questionneed simple accounting software source code in C#.... Pin
faradgi9-Nov-08 22:19
faradgi9-Nov-08 22:19 
AnswerRe: need simple accounting software source code in C#.... Pin
Simon P Stevens9-Nov-08 22:29
Simon P Stevens9-Nov-08 22:29 
GeneralRe: need simple accounting software source code in C#.... Pin
Dave Kreskowiak10-Nov-08 3:37
mveDave Kreskowiak10-Nov-08 3:37 
JokeRe: need simple accounting software source code in C#.... Pin
Paul Conrad10-Nov-08 5:15
professionalPaul Conrad10-Nov-08 5:15 
GeneralRe: need simple accounting software source code in C#.... Pin
R.Sheikh24-Oct-13 23:40
R.Sheikh24-Oct-13 23:40 
GeneralRe: need simple accounting software source code in C#.... Pin
Dave Kreskowiak25-Oct-13 3:27
mveDave Kreskowiak25-Oct-13 3:27 
AnswerSTOP SPAMMING THE FORUMS Pin
leckey10-Nov-08 11:08
leckey10-Nov-08 11:08 
GeneralRe: STOP SPAMMING THE FORUMS Pin
lincyang10-Nov-08 18:35
lincyang10-Nov-08 18:35 
QuestionPre - Information for user before mainapplication starts Pin
JuergenLissmann9-Nov-08 22:03
JuergenLissmann9-Nov-08 22:03 
AnswerRe: Pre - Information for user before mainapplication starts Pin
Giorgi Dalakishvili9-Nov-08 22:11
mentorGiorgi Dalakishvili9-Nov-08 22:11 
AnswerRe: Pre - Information for user before mainapplication starts Pin
AhsanS9-Nov-08 22:11
AhsanS9-Nov-08 22:11 
QuestionHow to get the Count of attachment in a particular mail Pin
Neeraj Kr9-Nov-08 21:04
Neeraj Kr9-Nov-08 21:04 
AnswerRe: How to get the Count of attachment in a particular mail Pin
Wendelius10-Nov-08 7:26
mentorWendelius10-Nov-08 7:26 
QuestionDatagrid problem while loading XML data Pin
DJ2459-Nov-08 20:14
DJ2459-Nov-08 20:14 
AnswerRe: Datagrid problem while loading XML data Pin
J a a n s9-Nov-08 20:31
professionalJ a a n s9-Nov-08 20:31 
GeneralRe: Datagrid problem while loading XML data Pin
Giorgi Dalakishvili9-Nov-08 20:38
mentorGiorgi Dalakishvili9-Nov-08 20:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.