LastIndexOf bug? [closed]

As per the docs: public int LastIndexOf (char value, int startIndex, int count) “The search proceeds from startIndex toward the beginning of this instance.” The first comma before index 223 occurs at index 221.

Return day Name in c#

Rather try something like MessageBox.Show(DateTime.Today.DayOfWeek.ToString()); DateTime.Today Property Gets the current date. Your problem is that DateTime date = new DateTime(DateTime.Now.Date.Day); evaluates to {01/Jan/0001 12:00:00 AM} The constructor you used was DateTime Constructor (Int64) Initializes a new instance of the DateTime structure to a specified number of ticks.

Prevent duplicates from array, based on condition [closed]

You can write your own extension method that works like the built-in LINQ methods: public static class Extensions { public static IEnumerable<T> DistinctWhere<T>(this IEnumerable<T> input, Func<T,bool> predicate) { HashSet<T> hashset = new HashSet<T>(); foreach(T item in input) { if(!predicate(item)) { yield return item; continue; } if(!hashset.Contains(item)) { hashset.Add(item); yield return item; } } } } … Read more

How to get ToolTip from WPF Data Grid Column Header (DataGridTemplateColumn) in code?

Put the TextBlock in the HeaderTemplate of the column: <DataGridTemplateColumn x:Name=”col”> <DataGridTemplateColumn.HeaderTemplate> <DataTemplate> <TextBlock Text=”Current” ToolTip=”Price” ToolTipService.InitialShowDelay=”0″ ToolTipService.Placement=”Top” ToolTipService.ShowDuration=”999999″ RenderOptions.BitmapScalingMode=”NearestNeighbor”/> </DataTemplate> </DataGridTemplateColumn.HeaderTemplate> </DataGridTemplateColumn> …and find it in using the VisualTreeHelper: private void Button_Click(object sender, RoutedEventArgs e) { var columns = FindVisualChildren<System.Windows.Controls.Primitives.DataGridColumnHeader>(dataGrid)? .ToArray(); if (columns != null) { int columnIndex = 1; if (columns.Length > columnIndex) … Read more

Smtp authentification required [duplicate]

You need to tell the SMTP client that you will not be using your windows credentials to access the SMTP, so add smtpClient.UseDefaultCredentials = false; above this line of code smtpClient.Credentials = new NetworkCredential(“[email protected]”, “password”); Also, gmail doesn’t allow impersonation, so mailMessage.From = new MailAddress(“[email protected]”); will have no effect – the emails will still appear … Read more