C
C#

help

❔ Any Danger to using Actions in this way?

VVelcer2/21/2023
public class Entity
{
public event Action<int> OnUpdateFrame;

internal void OnNewTick(int tick)
{
OnUpdateFrame?.Invoke(tick);
}
}

public class Frog : Entity
{
public Frog()
{
OnUpdateFrame += Frog_OnUpdateFrame;
}

private void Frog_OnUpdateFrame(int obj)
{
throw new NotImplementedException();
}
}

public class SuperFrog : Frog
{
public SuperFrog() : base()
{
OnUpdateFrame += SuperFrog_OnUpdateFrame;
}

private void SuperFrog_OnUpdateFrame(int obj)
{
throw new NotImplementedException();
}
}
public class Entity
{
public event Action<int> OnUpdateFrame;

internal void OnNewTick(int tick)
{
OnUpdateFrame?.Invoke(tick);
}
}

public class Frog : Entity
{
public Frog()
{
OnUpdateFrame += Frog_OnUpdateFrame;
}

private void Frog_OnUpdateFrame(int obj)
{
throw new NotImplementedException();
}
}

public class SuperFrog : Frog
{
public SuperFrog() : base()
{
OnUpdateFrame += SuperFrog_OnUpdateFrame;
}

private void SuperFrog_OnUpdateFrame(int obj)
{
throw new NotImplementedException();
}
}
Xx0rld2/21/2023
what is Frog_OnUpdateFrame ? you should have OnUpdateFrame protected to not allow external access
VVelcer2/21/2023
Thank you. So I want to use Actions to let higher level classes subscribe to the update method. I want to know if this is potentially going to hurt the performance of my code versus just using overrides.
Xx0rld2/21/2023
you can declare it virtual protected in your entity you can do a minimal usage and test the 2 way with Benchmark.NET
Llycian2/21/2023
if you're only going to do one handler for the event, a virtual method would be best
AAccord2/22/2023
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ LINQ: Group and extract all consecutive elements from List that match predicateExample: ```cs List<int> ints = new() {6,3,1,1,1,1,1,2,7,8,1,1,1,1,3,2,5,1,1,9,8,1,1,1,1,4,7,8,1} va❔ FlourineFx AMF classes without aliases.I doubt anyone who sees this has ever worked with FlourineFx directly, as it's a dead library for a ❔ Getting executors for a component?I need to figure out how to get executors for a C# class. I need to do this programmatically for man❔ help with maximising screen applicationhi!! i'm very new to c# and i'm currently working on the design of an application, but i'm strugglinAsync TCP server with many connectionsHow to create an async TCP server which can handle many connections without creating a dedicated thr❔ Does anyone know this Visual Studio Theme?Hi everyone! I was forced to reformat my PC the other day and having installed VS2022 (was using 20❔ Trigger collisions not being detected?I am following an official Unity course online, with a lab where you work on your own game, my code ❔ embed and unity app/game and interact with itguys someone know how could I implement an unity app in a C# app? I mean, I'd like to login to an u❔ Syncfusion XlsIO for BlazorI have a workbook with a mainsheet ("OverzichtJumbo") and multiple other sheets which I need to get ❔ Encryption issueHello everyone i need some help. I made this programm who take files from a sourcefolder and encrypt❔ Azure Blob storage and multi tenancy, how to get a list of blobs with a specific key?I've got an application based on the abp framework that gets a sentence from a user and is returning✅ Can't insert data in my ASP.NET databasei don't know what i'm doing wrong❔ How to access variable from AccessibilityObject ?I am trying to make canges to an old Winforms or Window forms application and my main goal is to pop❔ Why can i not override a Method from a class that extend a Interface```cs public interface IRegistry { public static readonly List<IRegistry> RegistryTypes = n❔ Windows Form helpI have the source code for an application that utilizes Windows Forms, but I have no experience work❔ Services collection life timeHi guys, is it possible to register some services later when the application up and running ? ### ❔ So I'm hammering my head against this Lambda API I trying get workingSo I followed the instructions out of one of the articles I read on AWS Lambda C# API did the conver❔ Best architectural design choice?If I have multiple instances of multiple apps all working to do similar things, and they all need th