А если б я работал официально и у меня была бы российская трудовая книжка с нужной записью, она прокатила бы за границей?
public sealed class UniqueStringGenerator
{
private const long MAX = 3486784401;
private readonly Random _random;
private readonly HashSet<long> _history;
public UniqueStringGenerator(int seed)
{
_random = new Random(seed);
_history = new HashSet<long>();
}
public UniqueStringGenerator()
{
_random = new Random();
_history = new HashSet<long>();
}
public string Next() => Format(NextNumber());
public void Reset()
{
_history.TrimExcess();
_history.Clear();
}
private long NextNumber()
{
if (_history.Count >= int.MaxValue)
{
throw new InvalidOperationException("Variants exceeded. Please reset");
}
var next = _random.NextInt64(0, MAX);
while (_history.Contains(next))
{
next = _random.NextInt64(0, MAX);
}
_history.Add(next);
return next;
}
private static string Format(long number) => string.Create<long>(10, number,
static (span, number) =>
{
// Алгоритм по-лучше придумать не смог.
// Проходимся по каждому биту числа, понемногу сужая выбор между числами в словаре.
const string DICTIONARY = "123456789";
for (var i = 0; i < span.Length; i++)
{
var range = 0..DICTIONARY.Length;
while (!range.Start.Equals(range.End.Value))
{
var length = range.End.Value - range.Start.Value;
var step = length / 2;
if (step == 0)
{
break;
}
if ((number & 1) == 0)
{
range = range.Start..(range.End.Value - step);
}
else
{
range = (range.Start.Value + step)..range.End;
}
number >>= 1;
}
span[i] = DICTIONARY[range.Start];
}
});
}
git clone git@github.com:morphIsmail/video_course_basic.git
git clone <адрес твоего форка>
cd <...>
git reset <commit hash того коммита, до которого хочешь откатиться>
# можно оставить всё в мастере, но тогда надо предыдущую команду вызывать с --hard и сделать потом git push --force
# а можно создать новую ветку через git branch и git checkout и потом запушить её через git push
var text = "123 321";
var statistics = new int[10];
var arrStr = text.Split(' '); // И не надо ничего предполагать. Под индексом 0 лежит 123
Console.WriteLine(arrStr[0][0]); // выдаст 1
// Ошибка из-за того что Convert.ToInt32(arrStr[0][0]) == 49 - это код символа '1'
// statistics[Convert.ToInt32(arrStr[0][0])] = 1; // ошибка переполнение массива
// Гарантируем, что arrStr[0][0] - цифра и парсим её.
var digit = arrStr[0][0];
var idx = digit is >= '0' and <= '9'
? digit - '0'
: throw new InvalidOperationException("Not a digit");
statistics[idx] = 1; // Нет ошибки
что я делаю не так подскажите пожалуйста?
SendPhoto msg = new SendPhoto();
msg.setChatId(chatId);
msg.setPhoto(id);
msg.setCaption(caption);
pub struct Animal {
pub name: String,
pub age: i32,
pub strength: i32,
}
pub struct Person {
pub name: String,
pub age: i32,
pub strength: i32,
}
// Выделяем новый трейт, который позволяет получить силу
trait Strength {
fn strength(&self) -> i32;
}
trait BaseTrait {
fn init(&self);
// В старом трейте принимаем target по ссылке и ограничиваем, что принимаем только такой target, который реализует trait Strength
fn stronger_than<T>(&self, target: &T) -> bool
where
T: Strength;
}
impl Strength for Person {
fn strength(&self) -> i32 {
self.strength
}
}
impl Strength for Animal {
fn strength(&self) -> i32 {
self.strength
}
}
impl BaseTrait for Person {
fn init(&self) {
println!("Hello, im Person: {}", self.name);
}
fn stronger_than<T>(&self, enemy: &T) -> bool
where
T: Strength,
{
self.strength > enemy.strength() // вызываем метод, вместо обращения к полю
}
}
impl BaseTrait for Animal {
fn init(&self) {
println!("Hello, im Animal: {}", self.name);
}
fn stronger_than<T>(&self, enemy: &T) -> bool
where
T: Strength,
{
self.strength > enemy.strength()
}
}
fn main() {
let person = Person {
name: String::from("John"),
age: 25,
strength: 12,
};
let animal = Animal {
name: String::from("Elephant"),
age: 5,
strength: 360,
};
person.init();
animal.init();
if person.stronger_than(&animal) {
println!("Person is stronger than animal");
}
if animal.stronger_than(&person) {
println!("Animal is stronger than person")
}
}
Нет связей - тебе придется трудно.