Можно попробовать SuperCopier, он заменяет стандартный механизм копии Windows, в то время как загружено.
Это может повторить отказавшие файлы в конце, возобновить отмененную копию (даже копия, отмененная Windows), принимает "Все" для каждого ответы. Можно даже ответить на раздражающие вопросы (файл уже существует, ошибка, копируя файл), прежде чем они произойдут.
The return type of a function must be typed. As with any other variable or operation, any type that inherits from the specified type is a valid return value (which is why object
allows anything as a value).
The logistics of the caller wouldn't make much sense; how would you know whether to type your variable as a char
or a string
in your example?
Is there a particular reason that you can't return a string
in all cases?
I don't think it's theoretically possible. You could use "dynamic" in C# 4, but if you're not there yet, you can't do that.
If it could return either a string or a character, then it has to be an object that both of those descend from, of which "object" is your only choice. And then you'd have to do casts.
C# (3.5 and previous) needs to know what the single return type of the method is so that it can do checking on the calling method. And in fact, in C#4, when you say "dynamic" it actually uses "object" underneath.
You could create a custom class/struct that has both
public class StringOrChar
{
char charValue;
string stringValue;
bool isString;
}
But it's kludgy.
Why do you want to have different return types?
Your can use out
parameters. or return a type that contains both variations.
есть много "left (str, 1) <'x'", но в других случаях это просто abc = left (str, 3)
В этом конкретном случае вы могли просто верните односимвольную строку. Сравнение строк работает в их лексикографическом порядке, поэтому здесь нет особой необходимости использовать символы (если, конечно, исходный автор не использовал полиморфизм для обработки символов иначе, чем строки, и в этом случае я вам сочувствую).
методы могут - насколько я знаю - возвращать только один тип
, так что return object и cast являются логической альтернативой
, однако обратите внимание, что если ваш дизайн вынудил вас к этому затруднительное положение, в нем может быть изъян; возможно, некоторые дополнительные сведения помогут нам
примечание: Джон Скит не подвержен всем таким ограничениям
What about this:
string right(string fullStr, int endPosition, out bool oneChar)
{
string result = fullStr.Substring(endPosition);
oneChar = result.Length == 1;
return result;
}
Are you trying to do this?
/// <summary>
/// Emulates VB Right Function
/// Returns a string containing a specified number of characters from the right side of a string.
/// </summary>
/// <param name="s"></param>
/// <param name="length">The number of characters to return.</param>
/// <returns>
/// The right <paramref name="length"/> number of characters from the string.
/// If the string has less than or equal to <paramref name="length"/> number of characters,
/// an empty string is returned.
/// </returns>
public static string Right(this string s, int length)
{
return length > s.Length ? string.Empty : s.Substring(s.Length - length);
}
When calling this method, you could do:
string myString = "Test String";
string returnedString = mystring.Right(1);
char? myChar = returnedString.Length == 1 ? returnedString[0] : null;
bool isReturnValueAChar = myChar.HasValue;
Enriquev,
Невозможно реализовать право без изменения синтаксиса из VBA. Вы можете указать, какой тип возвращаемого значения вам нужен, но это, по сути, приведение ...
public static U right<T, U>(T input, int index)
{
...
return (U)returnVariable;
}
Я действительно не думаю, что это решит вашу проблему.
Можно ли заменить регулярным выражением все отдельные символы, заключенные в одинарные кавычки ? Это превратит символы в строки и позволит вашим операторам сравнения работать.