/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/visualbasic/getting-started/ref-returns.cs
38 строк
923 B
Next Turn
Normalizes trailing spaces in samples, Part 1 (#17895)
17 апр 2020, 19:02
Не верифицирован
17 апр 2020, 19:02
63ee2a4
Код
Авторство
О чём код?
using System; public class Sentence { private string[] words; private int currentSearchPointer; public Sentence(string sentence) { words = sentence.Split(' '); currentSearchPointer = -1; } public ref string FindNext(string startWithString, ref bool found) { for (int count = currentSearchPointer + 1; count < words.Length; count++) { if (words[count].StartsWith(startWithString)) { currentSearchPointer = count; found = true; return ref words[currentSearchPointer]; } } currentSearchPointer = -1; found = false; return ref words[0]; } public string GetSentence() { string stringToReturn = null; foreach (var word in words) stringToReturn += $"{word} "; return stringToReturn.Trim(); } }