abstract class Particle
{
public int X { get; protected set; }
public int Y { get; protected set; }
public char C { get; protected set; } = '%';
public Particle(int _x, int _y)
{
X = _x;
Y = _y;
}
}
abstract class FallableParticle : Particle
{
protected FallableParticle(int _x, int _y) : base(_x, _y)
{
}
public abstract void Fall();
}
if (f.CanFall(ps))
{
f.Fall();
}
public bool Fall();
public bool CanFall { get; }
class Sand : FallableParticle
{
public Sand(int x, int y) : base(x, y) => C = '0';
public override void Fall() => Y += 1;
}
class Block : Particle
{
public Block(int x, int y) : base(x, y) => C = '#';
}
class ParticleStorage : IEnumerable<Particle>
{
readonly ImmutableArray<Particle> particles;
public ParticleStorage(IEnumerable<Particle> p) =>
particles = p.ToImmutableArray();
public bool IsParticleExists(int x, int y) =>
this.Any(p => p.X == x && p.Y == y);
public IEnumerator<Particle> GetEnumerator() =>
((IEnumerable<Particle>)particles).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() =>
((IEnumerable)particles).GetEnumerator();
}
class Mover
{
public void Move(ParticleStorage ps)
{
foreach (var p in ps.OfType<FallableParticle>())
{
if (!ps.IsParticleExists(p.X, p.Y + 1))
{
p.Fall();
}
}
}
}
static int ReadInt(Func<int, bool> filter)
{
while (true)
{
var a = Console.ReadLine();
bool a_number = int.TryParse(a, out int ai);
if (a_number && filter(ai))
{
return ai;
}
else
{
Console.WriteLine("Некорректные данные. Попробуйте еще раз.");
}
}
}
Console.Write($"\nВведите четное значение <a>: ");
var a = ReadInt(a => a % 2 == 0);
public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(GetGitCommitId());
hashCode.Add(GetGitCommitIdDescribeShort());
hashCode.Add(GetBuildTimeStamp());
hashCode.Add(GetProjectVersion());
hashCode.Add(GetCopyright());
hashCode.Add(GetLicense());
hashCode.Add(GetUrl());
hashCode.Add(GetBuildJDKVersion());
hashCode.Add(GetTargetJREVersion());
return hashCode.ToHashCode();
}
var jsonPath = "data.json";
using StreamReader reader = File.OpenText(jsonPath);
var jToken = JToken.ReadFrom(new JsonTextReader(reader));
var values =
jToken["relationships_followers"].Select(j =>
j["string_list_data"][0]["value"].ToObject<string>())
.ToArray();
public static double Average(Dictionary<string, int> stuff) => stuff.Values.Average();
static Array Combine(params object[] arr)
{
if (arr.Length == 0)
{
return null;
}
var totalSize = 0;
Type type = null;
foreach (Array inner in arr)
{
var innerType = inner.GetType();
type ??= innerType;
if (innerType != type)
{
return null;
}
totalSize += inner.Length;
}
var resultArr = Array.CreateInstance(type.GetElementType(), totalSize);
var currentSize = 0;
foreach (Array inner in arr)
{
Array.Copy(inner, 0, resultArr, currentSize, inner.Length);
currentSize += inner.Length;
}
return resultArr;
}
x:DataType="vm:MedicineViewModel"
<ListView.ItemTemplate>
<DataTemplate x:DataType="vm:MedicineViewModel">
<ViewCell>
<ViewCell.View>
<StackLayout>
<Label FontSize="Large" Text="{Binding Title}" />
<Label FontSize="Small" Text="{Binding Format}" />
<Label FontSize="Small" Text="{Binding Method}" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
public enum Role
{
Admin,
Manager,
Accountant
}
public class User
{
public User(string login, Role role)
{
Login = login;
Role = role;
}
public string Login { get; }
public Role Role { get; }
}
public static User GetUserOrNull(string login, string password)
{
using (var connection = new SqliteConnection(connectionString))
{
connection.Open();
using (var command = connection.CreateCommand())
{
var query =
@"SELECT role FROM users
WHERE login = @login AND password = @password";
command.CommandText = query;
command.Parameters.AddWithValue("login", login);
command.Parameters.AddWithValue("password", password);
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
// GetOrdinal на тот случай если будем возвращать другие значения
var role = reader.GetInt32(reader.GetOrdinal("role"));
return new User(login, (Role)role);
}
}
return null;
}
}
}
private void Vhod_Click(object sender, EventArgs e)
{
try
{
SHA1 hash = new SHA1();
var login = LoginField.Text;
var pHash = hash.Hash(PasswordField.Text);
var user = DataBase.GetUserOrNull(login, pHash);
if (user != null)
{
this.Hide();
var MainForm = new MainForm();
MainForm.Closed += (s, args) => this.Close();
MainForm.Show();
}
else
{
MessageBox.Show("Неверный логин или пароль! Пожалуйста,повторите попытку.", "Ошибка!");
LoginField.Text = "";
LoginField.Clear();
PasswordField.Text = "";
PasswordField.Clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var treeView = new TreeView
{
Dock = DockStyle.Fill
};
this.Controls.Add(treeView);
var dt = GetDataTable();
PopulateTreeViewFromDataTable(treeView, dt);
}
private DataTable GetDataTable()
{
var dt = new DataTable("Цемент");
dt.Columns.AddRange(new[] {
new DataColumn("Name"),
new DataColumn("NameOfCement")
});
dt.Rows.Add("Портланд", "Вихрь");
dt.Rows.Add("Романцемент", "Тайга");
dt.Rows.Add("Романцемент", "Свой");
dt.Rows.Add("Алумацемент", "Курон");
return dt;
}
public void PopulateTreeViewFromDataTable(TreeView tv, DataTable dataTable)
{
var data =
dataTable
.AsEnumerable()
.Select(row => new
{
Name = row.Field<string>("Name"),
Cement = row.Field<string>("NameOfCement")
})
.GroupBy(x => x.Name);
tv.Nodes.Clear();
var root = tv.Nodes.Add(dataTable.TableName);
foreach (var gr in data)
{
var node = root.Nodes.Add(gr.Key);
foreach (var subItem in gr)
{
node.Nodes.Add(subItem.Cement);
}
}
}
}
dataGridView1.Columns[j].DefaultCellStyle.BackColor = Color.Chartreuse;
dataGridView1[j, i].Style.BackColor = Color.Chartreuse;
private void task1_Click(object sender, EventArgs e)
{
int n1, n2;
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
for (int i = 0; i < dataGridView1.RowCount; i++)
{
if (int.TryParse(dataGridView1[j, i].Value.ToString(), out n1)
&& int.TryParse(dataGridView2[j, i].Value.ToString(), out n2))
{
if (n1 > n2)
{
dataGridView1[j, i].Style.BackColor = Color.Chartreuse;
}
else
{
dataGridView1[j, i].Style.BackColor = Color.White;
}
}
}
}
task2.Enabled = true;
}
[XmlRoot(ElementName = "radiostation")]
public class Radiostation
{
[XmlElement(ElementName = "country")]
public string Country { get; set; }
[XmlElement(ElementName = "genre")]
public string Genre { get; set; }
[XmlElement(ElementName = "subgenre")]
public string Subgenre { get; set; }
[XmlElement(ElementName = "title")]
public string Title { get; set; }
[XmlElement(ElementName = "urlwww")]
public string Urlwww { get; set; }
[XmlElement(ElementName = "ico")]
public string Ico { get; set; }
[XmlAttribute(AttributeName = "name")]
public string Name { get; set; }
}
[XmlRoot(ElementName = "users")]
public class Users
{
[XmlElement(ElementName = "radiostation")]
public Radiostation Radiostation { get; set; }
}
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
public class Questions
{
public string Question { get; set; }
public string Theme { get; set; }
public string Description { get; set; }
public string QuestionEn { get; set; }
public string DescrEn { get; set; }
}
const string FilePath = "sample.xls";
var qs = new List<Questions>();
using var stream = File.Open(FilePath, FileMode.Open, FileAccess.Read);
using var reader = ExcelReaderFactory.CreateReader(stream);
do
{
while (reader.Read())
{
var question = reader.GetString(0);
var theme = reader.GetString(1);
var description = reader.GetString(2);
qs.Add(new Questions()
{
Question = question,
Theme = theme,
Description = description
});
}
} while (reader.NextResult());
foreach(var q in qs)
{
Console.WriteLine($"{q.Question}");
Console.WriteLine($"{q.Theme}");
Console.WriteLine($"{q.Description}");
Console.WriteLine(new string('-', Console.WindowWidth));
}
Индейцы в знак примирения хлопали в ладоши
history
Они закапывали топор войны
----------------------------------------------------------------------------------------------------
Моряки пропитывали свою одежду смолой, чтобы она не рвалась
history
Чтобы она не пропускала воду
----------------------------------------------------------------------------------------------------
readonly int[] q;
public Form2(int[] q)
{
InitializeComponent();
this.q = q;
this.WindowState = FormWindowState.Maximized;
Size size = new Size(Screen.PrimaryScreen.WorkingArea.Width,
Screen.PrimaryScreen.WorkingArea.Height);
pictureBox1.Size = size;
pictureBox1.Paint += PictureBox_Paint;
}
private void PictureBox_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(Color.FromArgb(q[2], q[3], q[4]));
for (int i = 0; i < pictureBox1.Width; i += q[0])
{
for (int j = 0; j < pictureBox1.Height; j += q[0])
{
g.FillRectangle(new SolidBrush(Color.FromArgb(q[5], q[6], q[7])), i, j, q[1], q[1]);
}
}
}
char[] notAllowedSymbols = { '!', '#', '$', '%', '&', '(', ')', '*', ',', '+', '-' };
массив[индекс]
var firstChar = notAllowedSymbols[0]; // '!'
private static bool IsValid(string password)
{
char[] notAllowedSymbols = { '!', '#', '$', '%', '&', '(', ')', '*', ',', '+', '-' };
for (int i = 0; i < notAllowedSymbols.Length; i++)
{
if (password.Contains(notAllowedSymbols[i]))
{
return false;
}
}
return true;
}
public ObservableCollection<People> Peoples { get; } =
new ObservableCollection<People>();
private void LoadData()
{
Peoples.Clear();
if (File.Exists(_FileName))
{
using (var reader = new StreamReader(_FileName))
{
var xs = new XmlSerializer(typeof(People[]));
var arr = (People[])xs.Deserialize(reader);
foreach(var p in arr)
{
Peoples.Add(p);
}
reader.Close();
}
}
}
ItemSourse = "{Binding ElementName = window, Path= = _Peoples}"
ItemSourse = "{Binding Peoples}"