Click here to Skip to main content
15,888,401 members
Home / Discussions / C#
   

C#

 
AnswerRe: Solution Explorer > FOLDER > Text Files Pin
OriginalGriff14-May-18 0:15
mveOriginalGriff14-May-18 0:15 
QuestionGetting error Cannot access a disposed object. Object name: 'TreeView' Pin
ranimiyer1013-May-18 23:18
ranimiyer1013-May-18 23:18 
AnswerRe: Getting error Cannot access a disposed object. Object name: 'TreeView' Pin
Eddy Vluggen14-May-18 2:00
professionalEddy Vluggen14-May-18 2:00 
Questionc# unique character in char array Pin
swathiii12-May-18 2:44
swathiii12-May-18 2:44 
AnswerRe: c# unique character in char array Pin
Gerry Schmitz12-May-18 2:54
mveGerry Schmitz12-May-18 2:54 
QuestionRe: c# unique character in char array Pin
Richard MacCutchan12-May-18 3:32
mveRichard MacCutchan12-May-18 3:32 
AnswerRe: c# unique character in char array Pin
OriginalGriff12-May-18 4:16
mveOriginalGriff12-May-18 4:16 
AnswerRe: c# unique character in char array Pin
#realJSOP14-May-18 6:43
mve#realJSOP14-May-18 6:43 
C#
public class CharData
{
    public char Character { get; set; }
    public int Count { get; set; }
}

public class CharCounter : List<CharData>
{
    public CharCounter(char[] chars)
    {
        if (chars == null)
        {
            throw new ArgumentNullException("The character array parameter cannot be null.");
        }
        if (chars.Length == 0)
        {
            throw new InvalidOperationException("The character array cannot be empty.");
        }
        foreach(char ch in chars)
        {
            this.Add(ch);
        }
    }

    public void Add(char ch)
    {
        CharData cd = this.FirstOrDefault(x=>x.Character == ch);
        if (cd == null)
        {
            this.Add(new CharData(){Character = ch, Count=1});
        }
        else
        {
            cd.Count++;
        }
    }
}


Usage:

C#
CharCounter counter = new CharCounter(new char[]{'a','b','b','a','c'});
CharData unique = counter.FirstOrDefault(x=>x.Count == 1);
string msg = (unique == null) ? "No unique characters found":string.Format("First unique character is '{0}'", unique.Character);

".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

GeneralRe: c# unique character in char array Pin
Mycroft Holmes14-May-18 14:13
professionalMycroft Holmes14-May-18 14:13 
GeneralRe: c# unique character in char array Pin
#realJSOP15-May-18 3:46
mve#realJSOP15-May-18 3:46 
QuestionWinforms - Find Value in Collection Containing Instantiations of a Custom Class Pin
DabbingTree11-May-18 8:37
DabbingTree11-May-18 8:37 
AnswerRe: Winforms - Find Value in Collection Containing Instantiations of a Custom Class Pin
Richard Deeming11-May-18 9:04
mveRichard Deeming11-May-18 9:04 
AnswerRe: Winforms - Find Value in Collection Containing Instantiations of a Custom Class Pin
BillWoodruff11-May-18 23:43
professionalBillWoodruff11-May-18 23:43 
QuestioniTextSharp - Character problem Pin
User 1367511411-May-18 1:10
User 1367511411-May-18 1:10 
AnswerRe: iTextSharp - Character problem Pin
Luc Pattyn13-May-18 23:18
sitebuilderLuc Pattyn13-May-18 23:18 
QuestionA second form from the first form, but both are active Pin
trottl10-May-18 23:18
trottl10-May-18 23:18 
AnswerRe: A second form from the first form, but both are active Pin
OriginalGriff10-May-18 23:25
mveOriginalGriff10-May-18 23:25 
GeneralRe: A second form from the first form, but both are active Pin
trottl10-May-18 23:32
trottl10-May-18 23:32 
GeneralRe: A second form from the first form, but both are active Pin
OriginalGriff10-May-18 23:47
mveOriginalGriff10-May-18 23:47 
AnswerRe: A second form from the first form, but both are active Pin
BillWoodruff12-May-18 0:00
professionalBillWoodruff12-May-18 0:00 
QuestionMultiple clicks on one button scrolls through selection choices Pin
Member 1382104810-May-18 5:19
Member 1382104810-May-18 5:19 
SuggestionRe: Multiple clicks on one button scrolls through selection choices Pin
Richard Deeming10-May-18 5:55
mveRichard Deeming10-May-18 5:55 
AnswerRe: Multiple clicks on one button scrolls through selection choices Pin
OriginalGriff10-May-18 6:06
mveOriginalGriff10-May-18 6:06 
GeneralRe: Multiple clicks on one button scrolls through selection choices Pin
Luc Pattyn10-May-18 6:24
sitebuilderLuc Pattyn10-May-18 6:24 
GeneralRe: Multiple clicks on one button scrolls through selection choices Pin
OriginalGriff10-May-18 6:44
mveOriginalGriff10-May-18 6:44 

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.