Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
...А asmx только в iis
Были ещё вопросы совсем простые (как инвертировать строку?)
public string Reverse(string str)
{
char[] array = str.ToCharArray();
char temp;
for (int i = 0, len = Math.Floor((float)((array.Length - 1) / 2); i <= len); ++i)
{
temp = array[i];
array[i] = array[array.Length - (1 + i)];
array[array.Length - (1 + i)] = temp;
}
return new String(array);
}
for(int i = 0, len = (int)Math.Floor((float)((array.Length - 1) / 2)); i <= len; ++i)
...
for в Reverse2 с вашим), ни один из которых, однако, до конца верным не является:
using System;
using System.Diagnostics;
using System.Text;
namespace StringReversal
{
class Program
{
static void Main()
{
Console.WriteLine(Reverse1("Hello world!"));
Console.WriteLine(Reverse2("Hello world!"));
Console.WriteLine(Reverse3("Hello world!"));
Debug.Assert(Reverse1("Hello world!") == Reverse2("Hello world!") &&
Reverse2("Hello world!") == Reverse3("Hello world!"));
}
static string Reverse1(string source)
{
char[] chars = source.ToCharArray();
Array.Reverse(chars);
return new string(chars);
}
static string Reverse2(string source)
{
StringBuilder builder = new StringBuilder(source);
for(int i = 0; i < source.Length / 2; ++i)
{
char temp = builder[i];
builder[i] = builder[source.Length - i - 1];
builder[source.Length - i - 1] = temp;
} // for
return builder.ToString();
}
static string Reverse3(string source)
{
return
source.Length > 0
? source[source.Length - 1] + Reverse1(source.Substring(0, source.Length - 1))
: string.Empty;
}
}
}
Most Unicode characters can be represented by a single Char object, but a character that is encoded as a base character, surrogate pair, and/or combining character sequence is represented by multiple Char objects. For this reason, a Char structure in a String object is not necessarily equivalent to a single Unicode character.
static string Reverse4(string source)
{
return new string(new List<char>(ReverseImpl(SurrorgateAwareStringEnumerable(source))).ToArray());
}
static IEnumerable<T> ReverseImpl<T>(IEnumerable<T> source)
{
Stack<T> stack = new Stack<T>();
foreach(T value in source)
stack.Push(value);
return stack.ToArray();
}
static IEnumerable<char> SurrorgateAwareStringEnumerable(string source)
{
for(int i = 0; i < source.Length; ++i)
{
if(char.IsSurrogate(source[i]))
{
yield return source[i];
yield return source[++i];
} // if
else
yield return source[i];
} // for
yield break;
}
using System;
using System.Diagnostics;
using System.Text;
namespace StringReversal
{
class Program
{
static void Main()
{
Console.WriteLine(Reverse1("Hello world!"));
Console.WriteLine(Reverse2("Hello world!"));
Console.WriteLine(Reverse3("Hello world!"));
Debug.Assert(Reverse1("Hello world!") == Reverse2("Hello world!") &&
Reverse2("Hello world!") == Reverse3("Hello world!"));
}
static string Reverse1(string source)
{
char[] chars = source.ToCharArray();
Array.Reverse(chars);
return new string(chars);
}
static string Reverse2(string source)
{
StringBuilder builder = new StringBuilder(source);
for(int i = 0; i < source.Length / 2; ++i)
{
char temp = builder[i];
builder[i] = builder[source.Length - i - 1];
builder[source.Length - i - 1] = temp;
} // for
return builder.ToString();
}
static string Reverse3(string source)
{
return
source.Length > 0
? source[source.Length - 1] + Reverse1(source.Substring(0, source.Length - 1))
: string.Empty;
}
}
}
* This source code was highlighted with Source Code Highlighter.
ASP.NET, поиск работы, вопросы собеседований