lukkasz323
lukkasz323
CC#
Created by lukkasz323 on 4/29/2024 in #help
✅ Calling base of subscribed method results in a StackOverflowException
No description
65 replies
CC#
Created by lukkasz323 on 11/27/2023 in #help
I don't understand the error message in context to my code
List<List<int>> maze = new() { { 0, 1 }, { 2, 3 } };
List<List<int>> maze = new() { { 0, 1 }, { 2, 3 } };
This line of code results in CS1501 No overload for method 'Add' takes 2 arguments. My syntax is probably wrong, but wtf is going on the Error List?
3 replies
CC#
Created by lukkasz323 on 1/31/2023 in #help
❔ Move toolbar in Visual Studio 2022
4 replies
CC#
Created by lukkasz323 on 1/27/2023 in #help
❔ ✅ I can't convert List<BaseClass> to List<T> where T: BaseClass.
47 replies
CC#
Created by lukkasz323 on 1/25/2023 in #help
✅ Help me understand what a "God" class is and why/how should I avoid it.
37 replies
CC#
Created by lukkasz323 on 1/19/2023 in #help
❔ How can I reuse code without inheritance?
public interface IEntity
{
int Size { get; }
Vector2 Position { get; }
}
public interface IEntity
{
int Size { get; }
Vector2 Position { get; }
}
public class Player : IEntity
{
public int Size { get; } = 32;
public Vector2 Position { get; private set; }

public Player(Scene scene)
{
var spawnOffset = new Vector2(0, -3);

Position = new Vector2(
spawnOffset.X * scene.TileSize + scene.Room.Center.x - Size / 2,
spawnOffset.Y * scene.TileSize + scene.Room.Center.y - Size / 2);
}
}
public class Player : IEntity
{
public int Size { get; } = 32;
public Vector2 Position { get; private set; }

public Player(Scene scene)
{
var spawnOffset = new Vector2(0, -3);

Position = new Vector2(
spawnOffset.X * scene.TileSize + scene.Room.Center.x - Size / 2,
spawnOffset.Y * scene.TileSize + scene.Room.Center.y - Size / 2);
}
}
public class Enemy : IEntity
{
public int Size { get; } = 32;
public Vector2 Position { get; private set; }

public Enemy(Scene scene)
{
var spawnOffset = new Vector2(0, 0);

Position = new Vector2(
spawnOffset.X * scene.TileSize + scene.Room.Center.x - Size / 2,
spawnOffset.Y * scene.TileSize + scene.Room.Center.y - Size / 2);
}
}
public class Enemy : IEntity
{
public int Size { get; } = 32;
public Vector2 Position { get; private set; }

public Enemy(Scene scene)
{
var spawnOffset = new Vector2(0, 0);

Position = new Vector2(
spawnOffset.X * scene.TileSize + scene.Room.Center.x - Size / 2,
spawnOffset.Y * scene.TileSize + scene.Room.Center.y - Size / 2);
}
}
I'm trying to learn composition over inheritance, and so far so good, but the problem is that quickly there is a lot of complex code reuse, just take a look at both of these constructors, so much things I have to keep consistent between two classes. In case of inheritance I would just call the base class constructor, but what are my other possibilities here? The more of them, the better. Thanks.
21 replies
CC#
Created by lukkasz323 on 1/17/2023 in #help
❔ VS 2022 debugger ArgumentNullException not showing ParamName in quick info tooltip
10 replies
CC#
Created by lukkasz323 on 1/16/2023 in #help
❔ Are these properties the same? `{ get => x; }` vs `{ get; } = x;`
I would like to know if these have any other differences besides the syntax. Case 1: public int TileSize { get; } = 64; Case 2: public int TileSize { get => 64; } In my code below I have other properties that use the 2nd case, but that's because of more specific reasons, for example:
public (int x, int y) Center

{

get => (_terrain.GetLength(1) / 2, _terrain.GetLength(0) / 2);

}
public (int x, int y) Center

{

get => (_terrain.GetLength(1) / 2, _terrain.GetLength(0) / 2);

}
I'm not sure which one would be better in the long run (if there are no other differences). Previously I always used the 1st case, but here 2nd case seems more consistent with properties below, so this leaves a little confused as I never even thought about the 2nd case.
9 replies