|
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
|
|
|
|
|
Many thanks for your input.
Regards
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|
|
hello Friends,
i need simple accounting software source code in C# for learn more about accounting software projects . Please help me if possible
Thanx
|
|
|
|
|
|
From the sound of the project, I think he may already be familiar with Rent-A-Coder.
|
|
|
|
|
Dave Kreskowiak wrote: he may already be familiar with Rent-A-Coder
Sounds like it. Hmmm, a rent-a-coder going on to rent-a-coder to have another rent-a-coder to hire another rent-a-coder (and so on) ...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
|
You just replied to a 5 YEAR OLD post! Doing so is a complete waste of time.
|
|
|
|
|
FOUR forums with the same question?!?!?!
Blog link to be reinstated at a later date.
|
|
|
|
|
|
Good morning folks from germany.
My question is:
How can I show a pre-information like "Application starts.... please wait ...." (after a short startup/load-time) in a box or else to the user shortly after he had done the doubleclick on the application-icon on the desktop, while the main-application is starting in background. Its because the application is very big and takes a longer time to finalize the startup. The application is progammed in C# 2005 and .NET 2.0
Thanks for advance
|
|
|
|
|
What you need is called splash screen. There are several implementations here on codeproject so a simple search should return them
|
|
|
|
|
show Splash screen
Ahsan Ullah
Senior Software Engineer
MCTS 2.0
|
|
|
|
|
Below is the code I am using to get the unread emails, checking their subject and processing accordingly. The problem is that I am getting the exception "System.ArgumentException" which says "Cannot find the method on the object instance" on the line where I am trying to find out the number of attachments in a mail. The line is -
iAttachCnt = mailItem.Attachments.Count;
// Here is the complete code
private void WeeklyExpenses_Load(object sender, EventArgs e)
{
Outlook.NameSpace oNs;
Outlook.MAPIFolder oFldr;
int iAttachCnt;
DirectoryInfo di = new DirectoryInfo(System.Environment.CurrentDirectory.ToString() + "\\centralexpenses\\" + DateTime.Now.ToString("yyMMdd") + "\\");
if (!di.Exists)
{
di.Create();
}
string strPath = System.Environment.CurrentDirectory.ToString() + "\\centralexpenses\\" + DateTime.Now.ToString("yyMMdd") + "\\";
try
{
String sClassComp = "IPM.Note";
oOutlook = new Outlook.Application();
oNs = oOutlook.GetNamespace("MAPI");
oFldr = oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items newMailItems = null;
Outlook.MailItem mailItem = null;
Outlook.Attachments atmt = null;
newMailItems = oFldr.Items.Restrict("[unread] = true");
foreach (object item in newMailItems)
{
if (((Outlook.MailItem)item).MessageClass == sClassComp)
{
mailItem = (Outlook.MailItem)item;
if (mailItem.SenderEmailType == "EX")
{
string emailString = X4UMapi.GetMessageSenderAddress(mailItem.MAPIOBJECT).ToString();
int lastindex = emailString.LastIndexOf("=") + 1;
empEmail = emailString.Substring(emailString.LastIndexOf("=") + 1, ((emailString.Length - 1) - emailString.LastIndexOf("="))) + "@phfi.org";
}
else
{
empEmail = mailItem.SenderEmailAddress.ToString();
}
iAttachCnt = mailItem.Attachments.Count;
if (mailItem.Subject.ToString().ToUpper().Contains("Weekly Expenses") && iAttachCnt != 0)
{
foreach (Outlook.Attachment attachment in mailItem.Attachments)
{
string filename = attachment.FileName.ToLower();
if (filename.EndsWith(".xls"))
{
mailItem.UnRead = false;
filename = strPath + attachment.FileName;
flName = attachment.FileName;
attachment.SaveAsFile(filename);
Marshal.ReleaseComObject(attachment);
openandProcessExpenses(strPath, flName, empEmail);
smMail.sendMail(empName, empEmail, errorDescription);
}
}
}
else
{
if (iAttachCnt == 0)
{
errorDescription = "The Mail Sent By You is Not a Valid Email for Processing The Centrally Incurred Expenses As It Does Not Contain Any Attachments";
}
smMail.sendMail(empName, empEmail, errorDescription);
}
}
}
}
catch (System.Exception ex)
{
}
finally
{
GC.Collect();
oFldr = null;
oNs = null;
oOutlook = null;
}
}
-----Have A Nice Day-----
|
|
|
|
|
Not sure about this but what happens if you cast the mailItem to primary interface (_MailItem[^]):
iAttachCnt = ((_MailItem)mailItem).Attachments.Count;
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hai friends,
Iam creating an application that uses a datagrid with two combobox and two textbox columns.
Iam able to save the info from datagrid to XML file.
But when the time of opening XML file to datagrid it retrieves the datagrid error.
Please help me to remove this error and load XML data in to datagrid...
Thanks in advance
KP
|
|
|
|
|
With the details that you have provided, we wont be able to do anything else other than sharing this[^]link.
*jaans
|
|
|
|
|
|
Hai,
Sorry for delay. went for lunch
Piece of code
private RibbonStyle.RibbonButton rbtnOpen;
private System.Windows.Forms.DataGridView datagrid1;
private System.Windows.Forms.DataGridViewTextBoxColumn txtSlNo;
private System.Windows.Forms.DataGridViewTextBoxColumn txtEntities;
private System.Windows.Forms.DataGridViewComboBoxColumn cmbType;
private System.Windows.Forms.DataGridViewComboBoxColumn cmbSubType;
txtSlno : Auto generation
txtEntity : user data
cmbType : Combobox data(loaded programmatically)
cmbSubType : Combobox data(loaded programmatically)
I want to load the data from the XML file(explained below) to the datagrid while openning XML file.
<NewDataSet><br />
<EntityTable><br />
<SlNo>1</SlNo><br />
<Entity>X</Entity><br />
<Type>Data</Type><br />
<SubType>EIF</SubType><br />
</EntityTable><br />
<EntityTable><br />
<SlNo>2</SlNo><br />
<Entity>Y</Entity><br />
<Type>Data</Type><br />
<SubType>ELF</SubType><br />
</EntityTable><br />
<EntityTable><br />
<SlNo>3</SlNo><br />
<Entity>Z</Entity><br />
<Type>Transaction</Type><br />
<SubType>EI</SubType><br />
</EntityTable><br />
</NewDataSet>
Regards,
KP
|
|
|
|
|
i want to move the form at run time by holding it from any area of the from . not only by holding it from the title bar , any idea?
|
|
|
|
|
You will need to subscribe to mousedown, mousemove and mouseup events of the form. Then adjust location form's position accordingly.
|
|
|
|
|
The code below should help you
private bool IsPickedUp = false;
private void pnlTop_MouseDown(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
this.xPos = e.X;
this.yPos = e.Y;
this.IsPickedUp = true;
}
}
catch (Exception ex)
{
}
}
private void pnlTop_MouseMove(object sender, MouseEventArgs e)
{
try
{
Screen[] screens = Screen.AllScreens;
int width = screens[0].WorkingArea.Width;
int height = screens[0].WorkingArea.Height;
if (this.IsPickedUp)
{
Point temp = new Point(0, 0);
if (((this.Location.X + (e.X - this.xPos)) > 0) && (this.Location.X < (width - this.Width)))
{
temp.X = this.Location.X + (e.X - this.xPos);
}
else
{
if (e.X > this.xPos)
{
temp.X = (width - this.Width);
}
else if ((this.Location.X + (e.X - this.xPos)) > 0)
{
temp.X = this.Location.X + (e.X - this.xPos);
}
}
if ((this.Location.Y + (e.Y - this.yPos) > 0) && (this.Location.Y + (e.Y - this.yPos) < (height - this.Height)))
{
temp.Y = this.Location.Y + (e.Y - this.yPos);
}
else
{
if (e.Y > this.yPos)
{
temp.Y = (height - this.Height);
}
else if ((this.Location.Y + (e.Y - this.yPos)) > 0)
{
temp.Y = this.Location.Y + (e.Y - this.yPos);
}
}
this.Location = temp;
}
}
catch (Exception ex)
{
}
}
private void pnlTop_MouseUp(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
this.IsPickedUp = false;
}
}
catch (Exception ex)
{
}
}
Please note that i am using panel here. You can use any control and register above events from them.
Ahsan Ullah
Senior Software Engineer
MCTS 2.0
|
|
|
|
|
thanx, but could you please explaine me what is meant by all screens property, in the documentation it says ,takes all displays in the screen..
|
|
|
|
|
That's a non-standard interface. I recommend that you do not do it.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hello all,
Am planning to use Logging and Instrumentation Application Block to instrument our product. Any bad experiences?
Thanks.
|
|
|
|