Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
AnswerRe: windows 8 hybrid shutdown notification Pin
Richard Andrew x642-Feb-15 11:53
professionalRichard Andrew x642-Feb-15 11:53 
GeneralRe: windows 8 hybrid shutdown notification Pin
morglorf2-Feb-15 12:17
morglorf2-Feb-15 12:17 
GeneralRe: windows 8 hybrid shutdown notification Pin
morglorf3-Feb-15 5:54
morglorf3-Feb-15 5:54 
QuestionHelp with Array search. Pin
Member 114193361-Feb-15 18:18
Member 114193361-Feb-15 18:18 
AnswerRe: Help with Array search. Pin
Richard Andrew x641-Feb-15 18:34
professionalRichard Andrew x641-Feb-15 18:34 
GeneralRe: Help with Array search. Pin
Member 114193361-Feb-15 19:28
Member 114193361-Feb-15 19:28 
AnswerRe: Help with Array search. Pin
BillWoodruff1-Feb-15 21:16
professionalBillWoodruff1-Feb-15 21:16 
AnswerRe: Help with Array search. Pin
Richard Deeming2-Feb-15 2:53
mveRichard Deeming2-Feb-15 2:53 
You should try to avoid using goto - it makes your code harder to follow. There are almost always simpler ways to do what you want - for example:
C#
string Selected = Console.ReadLine();
while (Selected == "" || Selected.StartsWith(" "))
{
    Console.WriteLine("The Available names are : " + theSelected);
    Selected = Console.ReadLine();
}

There's no need to call .ToLower() on the strings to do a case-insensitive comparison; just pass StringComparison.OrdinalIgnoreCase to the StartsWith method:
C#
string[] first = Array.FindAll(names, name => name.StartsWith(Selected, StringComparison.OrdinalIgnoreCase));

Once you've found the matching names, you don't need to test whether the theSelected string contains the entered value; just test whether Array.FindAll returned any values:
C#
if (first.Length != 0)
{
    // There was at least one matching name.
}
else
{
    // There were no matching names.
}

You should also consider giving your variables better names, and using camel case for local variable names.
C#
string[] names = { "Omar", "-232" , "Don" , "Test" };
string joinedNames = string.Join(" ", names);

Console.WriteLine("The available names are : {0}", joinedNames);
Console.WriteLine("Which name do you need ? ");

string selected = Console.ReadLine();
while (string.IsNullOrEmpty(selected) || selected.StartsWith(" "))
{
    Console.WriteLine("The available names are : {0}", joinedNames);
    selected = Console.ReadLine();
}

string[] matchingNames = Array.FindAll(names, name => name.StartsWith(selected, StringComparison.OrdinalIgnoreCase));
Console.WriteLine("The names which start with {0} is / are :", selected.ToUpper());

if (matchingNames.Length != 0)
{
    Console.WriteLine(string.Join(Environment.NewLine, matchingNames));
}
else
{
    Console.WriteLine("None");
}

Console.ReadKey();




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


AnswerRe: Help with Array search. Pin
ramazan aktolu3-Feb-15 7:36
ramazan aktolu3-Feb-15 7:36 
QuestionTrouble binding with TCP to same local endpoint Pin
Mc_Topaz1-Feb-15 4:07
Mc_Topaz1-Feb-15 4:07 
AnswerRe: Trouble binding with TCP to same local endpoint Pin
Richard MacCutchan1-Feb-15 5:22
mveRichard MacCutchan1-Feb-15 5:22 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz1-Feb-15 5:27
Mc_Topaz1-Feb-15 5:27 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Richard MacCutchan1-Feb-15 6:05
mveRichard MacCutchan1-Feb-15 6:05 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz1-Feb-15 6:43
Mc_Topaz1-Feb-15 6:43 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
OriginalGriff1-Feb-15 7:43
mveOriginalGriff1-Feb-15 7:43 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
OriginalGriff1-Feb-15 5:38
mveOriginalGriff1-Feb-15 5:38 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Richard MacCutchan1-Feb-15 6:05
mveRichard MacCutchan1-Feb-15 6:05 
NewsRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz1-Feb-15 6:39
Mc_Topaz1-Feb-15 6:39 
AnswerRe: Trouble binding with TCP to same local endpoint Pin
Pete O'Hanlon2-Feb-15 6:31
mvePete O'Hanlon2-Feb-15 6:31 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz2-Feb-15 19:57
Mc_Topaz2-Feb-15 19:57 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Pete O'Hanlon2-Feb-15 23:18
mvePete O'Hanlon2-Feb-15 23:18 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz2-Feb-15 23:43
Mc_Topaz2-Feb-15 23:43 
AnswerRe: Trouble binding with TCP to same local endpoint Pin
DelphiCoder5-Feb-15 20:12
DelphiCoder5-Feb-15 20:12 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz8-Feb-15 8:00
Mc_Topaz8-Feb-15 8:00 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
DelphiCoder11-Feb-15 5:22
DelphiCoder11-Feb-15 5:22 

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.