c# logic to get the first non-repeating(distinct) character from the string
- by NoviceToDotNet
In c# i want to create logic that if i a string like abcabda is passed to a method then it should return first non repeative character from string like in above it should return c.
i am unable to convert a string to array of character then how to make comparison of each array character to the string and return the first non repeative character.
CanI make it like this?
class A
{
static void main()
{
A a=new A();
char ch=a.m1(abcabd);
}
}
class B
{
char m1(string s)
{
string s1=s;
char[] ch1=new char[s.length];
for(int x=0; x<s.length;x++)
{
ch1[x]=s[x];
}
for(int x=0; x<s.length; x++)
{
for(int y=0; y<s.lenth; y++)
{
if(s[x]=ch1[y])
{
/// here i am confused how to create logic for comparison please let me know
// and how to return the character
}
}
}
}
}