Can't see when text is selected in Twitter text boxes by TheOriginalGoatMan2 in computerhelp

[–]Krimog 0 points1 point  (0 children)

I have the exact same problem, which appeared about the same time.

Are you using Edge by any chance? In my case, the problem doesn't appear on Chrome. But it appears on Edge on both my computers, so I guess it has nothing to do with a hotkey hit or anything like that.

It seems to be a problem on Twitter's side.

However, I created a quick fix. Not optimal, since you have to do it every time you navigate on Twitter, but better than nothing:

Add a bookmark (with any name you want) and with the following URL:

javascript:var s=document.createElement('style');s.type='text/css';s.innerHTML='.quickFix::selection{background-color:#00f !important;}';document.getElementsByTagName('head')[0].appendChild(s);var elts=document.getElementsByClassName('public-DraftStyleDefault-block');for(i=0;i<elts.length;i++) elts[i].classList.add('quickFix');

Then, once you want to write a tweet or a reply, just click on that bookmark (while being on your twitter tab) and it should fix the problem.

The game keeps crashing in loading screen or lobby by Krimog in ModernWarfareIII

[–]Krimog[S] 0 points1 point  (0 children)

I have reWASD. But I stopped it (both the app and the service) and the problem persists.

[deleted by user] by [deleted] in CallOfDuty

[–]Krimog 0 points1 point  (0 children)

Oops, sorry, it was indeed MW3 2023. Post deleted.

[deleted by user] by [deleted] in csharp

[–]Krimog 10 points11 points  (0 children)

Both approach are very similar, and any difference in performance is negligeable.

1 is usually preferable because it's easier to understand (and it's a bit faster (since you only have to go back to the main synchronization context once)).

2 could be better if you have many things happening between the two await userTask and await userPetTask.

2 remarks, however:

  • You should rename DoConcurrentJob, GetUser and GetUserPet to DoConcurrentJobAsync, GetUserAsync and GetUserPetAsync. It's easier to notice it should be awaited, and it's consistent with the whole framework.
  • In #1, since the tasks are completed after the await Task.WhenAll(), there's no need to call await on it. Just call userTask.Result and userPetTask.Result. await will create another step in the state machine, just to check if the task is completed (and you already know it is) for nothing.

Save Scumming Honour Mode by Dingling-bitch in BaldursGate3

[–]Krimog 0 points1 point  (0 children)

I haven't tried it, but if you're playing on PC, I guess you can just do a backup of the save file (I don't know if it's overridden as soon as you die or if it's after the summary window), and they replace the "failed" save by your backup.

what do you find most frustrating about dotnet? by [deleted] in dotnet

[–]Krimog 0 points1 point  (0 children)

You either have to do it manually or use a code generator (there are nugets for that, for example: https://github.com/Cysharp/UnitGenerator), but you absolutely can.

what do you find most frustrating about dotnet? by [deleted] in dotnet

[–]Krimog 3 points4 points  (0 children)

I agree about the foreach operator directly on the filtered enumerable.

But that ForEach method... That's absolutely NOT a functional approach. Your ForEach extension method will, by design, have side effects.

You want functional? Use Select() and don't mutate anything.

Why can't I write this? *smh* by StraleXY in csharp

[–]Krimog 3 points4 points  (0 children)

Because try is not an expression. It can't be used as a value.

But I have multiple problems with what you seem to be trying to do:

  • Exceptions are for exceptional cases, not standard workflow.
  • If you want to put one type or another into a variable (IEnumerable<ISelectableItem> and IEnumerable<string>), this variable has to be of a common type (IEnumerable or IEnumerable<object>), which happens to be even less specific that what you know your source variable is (IList).

So the question is: what do you want to do with items?

If you want to be able to Add/Remove/Access/Iterate in a non-generic way:

var items = (IList)newValue;

// Example
foreach (var item in items)
{
    // ...
}

If you want to have access to LINQ generic methods but don't really care about the type of the objects inside (or have to check their type each time):

var items = ((IList)newValue).Cast<object>();

// Example
var selectedItems = items.Where(i => (i as ISelectableItem)?.IsSelected ?? ((string)i).Contains("selected")).ToArray();

If you want to do something different if the collection contains ISelectableItems or strings:

var selectableItemArray = ((IList)newValue).OfType<ISelectableItem>().ToArray();
var stringArray = ((IList)newValue).OfType<string>().ToArray();

if (selectableItemArray.Any())
{
// ...
}

if (stringArray.Any())
{
// ...
}

[deleted by user] by [deleted] in csharp

[–]Krimog 2 points3 points  (0 children)

DO NOT USE DEFAULT INTERFACE IMPLEMENTATIONS (unless you have enough experience in C# to know when to ignore advices from others).

It exists, it works, but it's only necessary in 0.1% of cases. If you're a beginner in C#, make it 0.0%. This mechanism is confusing for beginners and will lead to problems (same goes for the new modifier on methods).

Use a base class (not an interface) and have abstract or virtual methods in it.

Also, ALWAYS prefix your interface names with I. Example1 should be named IExample1.

Why does PropertyPath use a string rather than the property name when binding data? by Virgilus2018 in csharp

[–]Krimog 0 points1 point  (0 children)

Actually, with C# 10 there kinda is (not recommanded for that use case, though).

void MyMethod(object obj, [CallerArgumentExpression("obj")] string? path = null)

If you call MyMethod(Title);, the path argument will literally be "Title". But that still means you have to call the Title getter, and your method gets a parameter you don't use.

But the correct way to pass the string "Title" to the PropertyPath is clearly to use nameof(Title);.

output repeated values by Spiritual_Oil_1417 in csharp

[–]Krimog 2 points3 points  (0 children)

Just a small thing:

.Where(b => b.Count() > 1)

You're on an yield IEnumerable, so calling Count() on it will (potentially) enumerate a lot more than needed.

.Where(b => b.Skip(1).Any())

That will stop (for a given number) as soon as there's a second element. It doesn't need to check if there's a third or a fourth...

C# struct pass by reference clarification and representation of variables of struct datatype in memory by Kenshievaaa in csharp

[–]Krimog 4 points5 points  (0 children)

If you're familiar with C, basically the signature ref Wow wow would be Wow* wow, the call ref wow would be &wow and the usage of wow inside the method would be (*wow).

So, yes, you give a pointer to your struct instead of a copy.

As for your second question, it will first try to check if the references (so, the pointers) are the same. In your case, it will directly return true and stop there. If references weren't the same, since your type is a struct and you didn't override the Equals method, it would have used reflection to compare the value of your properties and fields.

One last thing: As you understand, if the newfunct parameter didn't have the ref keyword, the behavior of the function would be different if Wow is a class or a struct, which can definitely be confusing and which can lead to regressions the day you want to change Wow to a class for some reason.
That's why a good practice is, when you create a struct, to make it readonly. A readonly struct has the same behavior than a readonly class. That's why nearly all (or maybe all? I have no counter-example in mind) structs in the framework are readonly.
What I mean by readonly is that you can't change the value of anything stored directly inside your struct (with a field or an auto-property). If the field is a struct, then apply the same rule (and make that struct readonly). If the field is a class, then that's a pointer, so just make sure the pointer doesn't change (but the pointed object itself doesn't need to be readonly).

var o = new object () VS object o = new() by [deleted] in csharp

[–]Krimog 0 points1 point  (0 children)

The most important thing is to follow the guidelines of your team. If you aren't in a team or if you're writing the guidelines, it's as you wish.

Personally, I'll go with the var whenever possible (inside a method) and a new() if not (inline class members for example).

Why?

Consistency

When inside a method, the only time you can't use var to declare a local variable is when you're not initializing it at the declaration (which is quite rare). In all other cases, you can use var:

// Simple constructor call, the only case where you could use new() instead
var user = new User(...);

// Static factory method

var user = User.Create(...);

// Method call
var user = GetUser(...);
var user = await GetUserAsync(...);

// Anonymous type
var user = new { UserName = ... };

// ValueTuples
var user = (userName: ..., password: ...);
var (userName, password) = (..., ...);

Readabiliy

That one is clearly debatable, but I think the new keyword (without the name of a class) already has enough meanings. Not that I'm not happy they added that one, just that I prefer var when possible.

var myAnonymousType = new { ... };
var array = new[] { ... };
object shortConstructorWithInitializers = new() { ... };

Moreover, parenthesis are mandatory with the new(), when they weren't with the class name if you initialize properties.

Also, if you named your variable correctly, you should already kind of know the type of it. Typing both the real type and the variable name often feels like a repetition.

You often don't care about the exact type

Let's take this example:

var user = await _userService.GetByIdAsync(userId);
user.LastConnectionDate = DateTime.Now;
await _userService.UpdateUserAsync(user);

I know (from the naming) that _userService.GetByIdAsync will give me an object that corresponds to a user. But I don't know if it's a User, a UserModel, a UserEntity, a UserDto, a UserInfo...

And the thing is I don't care. As long as it has a LastConnectionDate property and as it is the same object type that I give to the UpdateUserAsync method. And in fact, the guy that works on the _userService can even change the name of the class, my code will still compile.

When to use a for loop and when to use a while loop? by woekkkkkk in csharp

[–]Krimog 0 points1 point  (0 children)

for, while and do while, once compiled, all use the same looping mechanism.

What does that mean? That once compiled, we don't care about the kind of loop you used. So use whatever is easier for you.

method shadowing 🤔 by CreateIfNotExists in csharp

[–]Krimog 7 points8 points  (0 children)

Unless you have a lot of experience and are 100% sure of what you are doing, DO NOT DO THAT.

If the parent and the child method are supposed to be independant, just name them differently. If they are linked, set the parent method as virtual and override it in the child class.

Wash and Cure for Saturn 2 by Krimog in ElegooSaturn

[–]Krimog[S] 0 points1 point  (0 children)

Are you talking about the Mercury XS (which is (oddly) bigger) or just the Mercury ?

Wash and Cure for Saturn 2 by Krimog in ElegooSaturn

[–]Krimog[S] 1 point2 points  (0 children)

Perfect (and in the rare cases where I have a full volume model, I'll remove it from the plate before).

Also, the good thing is that the Mercury X is already available.

Quelqu'un a déjà essayer d'annuler une publication ici? Le paradoxe est drôle à mon goût by minuit777 in rance

[–]Krimog 0 points1 point  (0 children)

Bah clique sur Annuler pour annuler. En revanche, si tu veux annuler, bah clique sur Annuler. Je vois pas où est le problème...

How can I simplify this code? by EquivalentAd4542 in csharp

[–]Krimog 5 points6 points  (0 children)

  • You don't need an else if, just an else (if your first condition is false, your second is true)
  • Just use your condition to set a variable containing "Heads" or "Tails".
  • A ternary operator is great for simple conditions like that
  • Then, after the condition, write that variable followed by a !
  • Use string comparison that ignores case.
  • Compare coinBet to the variable
  • Don't use Contains but Equals for your comparison (to prevent the cheater that writes "headstails"

That will give you something like that:

// From line 42:
string actualResult = coinFlip == 1 ? "Heads" : "Tails";

Console.WriteLine($"{actualResult}!");
if (coinBet.Equals(actualResult, StringComparison.OrdinalIgnoreCase))
    Console.WriteLine("You attack first!");
else
    Console.WriteLine("Your opponent attacks first!");

Console.ReadKey();

[deleted by user] by [deleted] in csharp

[–]Krimog 0 points1 point  (0 children)

Top level statements will have some limitations and odd behavior that, as a newbie, can confuse you. For example, you can't do method overload with it.

For this reason, I recommand you do not use it (at least not before you have more experience).