In C#, classes are foundational to object-oriented programming (OOP). They encapsulate data for the object and methods to manipulate that data. Along with class structures, there are other constructs like interfaces and abstract classes which help in defining contracts, encapsulating functionality, and providing a blueprint for objects.
Example classesMethod overloading and overriding are fundamental features in C#'s support for polymorphism. They help achieve both compile-time and run-time polymorphism.
In C#, method overloading allows a class to have multiple methods with the same name but with a different parameter list.
Overriding, on the other hand, is when a derived class provides a specific implementation for a method that is already defined in its base class or one of its base classes. The method in the derived class should have the same name, return type, and parameters as the method in the base class.
Examples Overloading and OverridingWith .http files in Visual Studio 2022, ASP.NET Core's minimal APIs are an excellent tool for quickly and succinctly defining web APIs.
Read more...Microsoft Content
Microsoft Learn http file testsSOLID stands for five principles that help in designing software architecture that is easy to manage and maintain:
DRY stands for "Don't Repeat Yourself". The DRY principle is a best practice in software development that recommends developers to avoid writing duplicate code. This can be achieved by abstraction, encapsulation, inheritance, and others.
Use Mapperly to map your objects. Mapperly
dotnet add package Riok.Mapperly --version 1.0.0
Advanced C# Programming Course C# Advance YouTube
React is a JavaScript library developed by Facebook for building user interfaces. It allows developers to create reusable UI components and manage state efficiently, leading to dynamic and interactive web apps.
React Hooks React prevState / prevPropsNext.js is a leading framework built on React that enables server-side rendering, static site generation, and routing capabilities to produce optimized and scalable web applications.
Next.js 13 NotesThe project showcased here serves as a practical example of a web application built using a robust technology stack featuring React, Vite, and TypeScript. Vite is a modern build tool engineered to offer a streamlined and efficient development experience for contemporary web applications. The project uses a C# Minimal API backend to serve the React frontend. There is a JWT authentication system in place to protect the API endpoints. The tool is segmented into two main components:
Explore Live Example: Visit AI Art Collector
A simple API built using FastAPI that interacts with a SQLite database to retrieve and filter person records based on age and gender. It provides three different endpoints: one that returns the data in JSON format, one that returns the data in HTML format, and a default root endpoint that confirms the API is working successfully.
FastAPIwithDBcallsExampleWelcome to the LearnPython.org interactive Python tutorial.
Read more...The `MERGE` statement, often referred to as an "upsert", allows you to insert, update, or delete records in one table based on the source data from another table.
MERGE example`UNION` is used to combine the result sets of two or more SELECT statements. It removes duplicate rows. `UNION ALL` does the same, but it doesn't remove duplicate rows.
UNION and UNION ALL examplesUDFs allow you to define your own T-SQL functions that can accept 0 or more parameters and return a single scalar data value or a table data type.
UDF example
Stored procedures in SQL Server are precompiled collections of one or more SQL statements. They offer the ability to encapsulate logic, can accept parameters, and return results. A key benefit of stored procedures is their capability to integrate robust error handling and transactions. Transactions ensure that a series of operations are treated as a single unit, with an all-or-none execution guarantee. They are controlled by BEGIN TRANSACTION
, COMMIT
, and ROLLBACK
commands, safeguarding data integrity. Moreover, the TRY-CATCH
construct in SQL Server further enhances error management within stored procedures. If any error arises in the TRY
block, control diverts to the corresponding CATCH
block, enabling precise error handling procedures, such as logging or resource cleanup.
SQL Joins are used to retrieve data from multiple tables based on logical relationships between them. There are different types of joins: INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.
Joins exampleSubqueries are SQL queries nested inside another query. They can be used with SELECT, INSERT, UPDATE, and DELETE statements.
Subquery exampleIndexes are used to retrieve data from the database more quickly. They are similar to an index in a book and can be created on one or more columns of a table.
Indexing exampleA view is a virtual table based on the result-set of an SQL statement. It contains rows and columns, just like a real table, but doesn't store data physically.
Views exampleTriggers are special types of stored procedures that are automatically executed (or fired) when a specific event occurs in the database, such as INSERT, UPDATE, or DELETE operations.
Triggers exampleA CTE provides the means to temporarily result a dataset which can be easily referenced within a SELECT, INSERT, UPDATE or DELETE statement.
CTE exampleWindow functions operate on a set of rows and return a single aggregated value for each row. Common examples include ROW_NUMBER(), RANK(), and DENSE_RANK().
Window Functions exampleConstraints are used to specify rules for data in a table. Common constraints include PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, and CHECK.
Aggregate functions perform a calculation on a set of values and return a single value. Common examples include COUNT(), SUM(), AVG(), MAX(), and MIN().
The `DBCC CHECKIDENT` command is used in SQL Server to check the current identity value for a table (if it's an identity column) and can also be used to manually set a new starting value for the identity column (known as reseeding). For instance, to reset the counter of an identity column in a table named "MyTable" to start with 1, you would use the command DBCC CHECKIDENT ('MyTable', RESEED, 0);
. Be cautious as reseeding can lead to duplicate values or gaps in the sequence if not managed correctly. Always backup data before performing such operations.
Normalization is the process of efficiently organizing data in a database. The main aim is to eliminate redundancy and improve data integrity.
Test-Driven Development (TDD) is a methodology where developers first write failing tests for a new feature or improvement. They then write code to pass the tests and refactor for optimal standards. This "test first" approach ensures code accuracy, maintainability, and resilience.
Using MSTest framework, I have developed a suite of tests for a simple calculator application. The tests cover basic arithmetic operations, and also delve into more complex scenarios, ensuring robustness of the calculator's functionalities.
CalculatorTestsExampleIn the ASP.NET MVC framework, there are three primary mechanisms to pass data from the controller to the view.
ViewBag
ViewData
TempData
MVC Data Transfer MechanismsASP.NET Core MVC introduces Tag Helpers to render HTML dynamically. These Tag Helpers simplify the process of binding server-side content within HTML tags.
asp-for
asp-action
asp-controller
asp-route
asp-area
asp-validation-for
asp-validation-summary
MVC Tag Helpers