What is the best practice ?

Laurent Guigon 311 Reputation points
2023-04-04T09:35:55.8766667+00:00

Hello I Just want to know what is the best practice between these 2 ways of implementation/code structure : First is :
Capture d'écran 2023-04-04 112756

Capture d'écran 2023-04-04 113217

second is :
Capture d'écran 2023-04-04 112815

Capture d'écran 2023-04-04 113358

May be 1st is for Web Assembly and 2nd for Blazor Server ? (it is the case, these are from 2 tutorials).

Developer technologies | .NET | Blazor
{count} votes

Accepted answer
  1. Anonymous
    2023-04-05T02:54:44.3966667+00:00

    Hi @Laurent Guigon , The first image you have shared is called the Partial class support for the component, Components are generated as C# partial classes and are authored using either of the following approaches:

    • A single file contains C# code defined in one or more @code blocks, HTML markup, and Razor markup. Blazor project templates define their components using this single-file approach.
    • HTML and Razor markup are placed in a Razor file (.razor). C# code is placed in a code-behind file defined as a partial class (.cs).

    The second image you have shared is called the Specify a base class, which is used to specify a base class for a component. For example, if multiple components contains the same attribute BlazorRocksText, then you could inherit a base class to provide the component's properties BlazorRocksText and methods. ***************************************************** 
    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".   Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.  

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.