delegate int Math(int x, int y); //вынеси в глобальные переменные
var actions = new Dictionary<string, Math>()
{
{"+", (x, y) => x + y},
{"-", (x, y) => x - y},
{"/", (x, y) => x / y},
{"*", (x, y) => x * y},
};
var random = new Random();
foreach (var action in actions)
{
var x = random.Next(1, 100);
var y = random.Next(1, 100);
Debug.WriteLine($"{x} {action.Key} {y} = {action.Value(x, y)}");
}
Regex.Replace(str, "[ ]+", " ")
public class Word
{
public Word(int index)
{
Index = index;
}
public int Index { get; set; }
}
var text = "Мама мыла папу + big space!";
const char findWord = ' ';
var wordsDictionary = new List<List<Word>>();
var count = 0;
var words = new List<Word>();
for (var index = 0; index < text.Length; index++)
{
var word = text[index];
if (word == findWord)
{
words.Add(new Word(index));
count++;
}
else if(count > 0 && word != findWord)
{
wordsDictionary.Add(new List<Word>(words));
words.Clear();
count = 0;
}
}
wordsDictionary.Reverse();
foreach (var lettersList in wordsDictionary)
{
lettersList.Reverse();
text = lettersList.Skip(1).Aggregate(text, (current, letter) => current.Remove(letter.Index, 1));
}
MessageBox.Show(text);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(String.Format("{0}", reader[0]));
}
[System.Serializable]
string json = JsonUtility.ToJson(classData);
System.IO.File.WriteAllText("json.json", json);
sw.WriteLine(text);
sw.WriteLine(string.join(Environment.NewLine, text));
public class Item
{
public Item(string name, int id, double cost)
{
Name = name;
Id = id;
Cost = cost;
}
public string Name { get; set; }
public int Id { get; set; }
public double Cost { get; set; }
public override string ToString()
{
return $"Id: {Id}, Name: {Name}, Cost: {Cost}";
}
}
static void Main(string[] args)
{
var findName = "Ball";
var items = new List<Item>
{
new Item("Ball", 10, 3),
new Item("Toy", 14, 15)
};
var item = items.FirstOrDefault(product => product.Name.Contains(findName));
if (item != null)
{
item.Cost = 100;
item.Id = 999;
}
Console.WriteLine(string.Join(Environment.NewLine, items));
Console.ReadKey();
var text = Console.ReadLine();
var textArray = text?.ToCharArray();
for (var i = textArray.Length - 3; i < textArray.Length; i++)
{
textArray[i] = char.ToUpper(textArray[i]);
}
Console.WriteLine(textArray);
Console.ReadKey();
var text = Console.ReadLine();
var textArray = text?.ToCharArray();
textArray = textArray.Take(textArray.Length - 3).Concat(textArray.Skip(textArray.Length - 3).Select(char.ToUpper)).ToArray();
Console.WriteLine(textArray);
Console.ReadKey();
Format specifier Name Description Examples
"C" or "c" Currency Result: A currency value.
Supported by: All numeric types.
Precision specifier: Number of decimal digits.
Default precision specifier: Defined by NumberFormatInfo.CurrencyDecimalDigits.
More information: The Currency ("C") Format Specifier. 123.456 ("C", en-US) -> $123.46
123.456 ("C", fr-FR) -> 123,46 €
123.456 ("C", ja-JP) -> ¥123
-123.456 ("C3", en-US) -> ($123.456)
-123.456 ("C3", fr-FR) -> -123,456 €
-123.456 ("C3", ja-JP) -> -¥123.456