using System;
using System.Linq;
class Program
{
static void Main()
{
Console.WriteLine(GetLastStanding(11, 4));
}
static int GetLastStanding(int n, int step)
{
var items = Enumerable.Range(0, n)
.Select(position => new Item { Position = position }).ToArray();
var i = 0;
var stepCounter = 0;
var nCounter = n;
while (nCounter > 1)
{
if (!items[i].Marked && ++stepCounter == step)
{
stepCounter = 0;
items[i].Marked = true;
--nCounter;
Console.WriteLine(string.Join(", ",
items.Select(item => item.Marked ?
"_" : (item.Position + 1).ToString())));
}
i = (i + 1) % n;
}
return items.Single(item => !item.Marked).Position;
}
struct Item
{
public int Position;
public bool Marked;
}
}
void MyMethod()
{
Func<int> pamar1 = () => 1 * 2;
Func<int> pamar2 = () => 3 * 4;
Func<int> pamar3 = () => 5 * 6;
for (var i = 0; i < 10; ++i)
{
DoMethod(pamar1, pamar2, pamar3);
}
}
void DoMethod(Func<int> pamar1, Func<int> pamar2, Func<int> pamar3)
{
Console.WriteLine(pamar1() * pamar2() * pamar3());
}
static void Main(string[] args)
{
var criteria = new Expression<Func<string, bool>>[]
{
str => str.Contains("дом"),
str => str.EndsWith("!"),
str => str.Substring(0, 1).ToUpper().Equals(str.Substring(0, 1)),
};
var complexCriterion = "1 | (2 & 3)";
var ep = new ExprParser();
LambdaExpression lambda = ep.Parse("(string str) => " + BuildComplexCriterion(complexCriterion, criteria));
var result = ep.Run(lambda, "дом");
}
static string BuildComplexCriterion(string complexCriterion, Expression<Func<string, bool>>[] criteria)
{
for (var i = 0; i < criteria.Length; ++i)
{
complexCriterion = complexCriterion.Replace((i + 1).ToString(), criteria[i].Body.ToString());
}
return complexCriterion;
}
dynamic myDinamic = GetDynamic();
myDynamic.SomeMethod();
using System;
using System.Linq;
using System.Xml.Linq;
namespace ConsoleApplication11
{
internal class Program
{
private static void Main(string[] args)
{
var xml = XDocument.Load("XMLFile1.xml");
Console.WriteLine(GetErrorText(706, xml));
Console.ReadLine();
}
private static string GetErrorText(int name, XDocument xDoc)
{
return xDoc.Root.Elements().First(el => int.Parse(el.Attribute("name").Value) == name).Value;
}
}
}
richTextBox1.Text = "blah blah meeh";
richTextBox1.SelectionStart = 5;
richTextBox1.SelectionLength = 4;
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Underline);
// еще варианты:
//richTextBox1.SelectionColor = Color.Red;
//richTextBox1.SelectionBackColor = Color.Yellow;
//повторить для все слов с ошибками