Skip to main content

Posts

CRUD operations in web api using net 6.0

.NET 6.0 - CRUD API Example and Tutorial This tutorial gives you step by step implementation of creating CRUD operations using ASP.NET Web API Core. This tutorial builds API for its clients to manage employee. it shows how to configure the SQL server connection to manage CRUD operations in real-time applications. Let's start step by step. 1. Create ASP.NET Web API Project Open your Visual Studio and select New Project from File Menu.     Now enter the name of the application and click next.   Next select framework .net 6 from drop down and enable open API (Swagger) support and click on create to create default project template for API.   2. Now Add Model to Employee Web API In this step, you will add the Employee Model Class which will define database entity. Right click on the project from solution explorer and select Add -> New Folder . Enter folder name as Models . Right click on the Models folder and select Add -> Class and add class file with name

How to do Alignment within string.Format in C#

Align String with Spaces [C#] This example shows how to align strings with spaces. The example formats text to table and writes it to console output. To align string to the right or to the left use static method String.Format. To align string to the left (spaces on the right), use negative number like below String.Format("{0,–10}", text) To align string to the right (spaces on the left), use postive number like below String.Format("{0,10}", text) Following example shows how to format text to the table. Values in the first and second column are aligned to the left and the third column is aligned to the right. Console.WriteLine("-------------------------------"); Console.WriteLine("First Name | Last Name | Age"); Console.WriteLine("-------------------------------"); Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Adam", "Gilchrist", 50)); Console.WriteLine(String.Format("{0,-10

Access Modifiers in C#

How many access modifiers in c# In this article, we will learn about the access modifiers in C#. 1. Public Access Modifier in C# The class member, that is defined as a Public can be accessed by other class members that are initialized outside the class. A public member can be accessed from anywhere even outside the namespace. public class Vehicle { public void Color() { Console.WriteLine("Vehicle color red"); } } 2. Private Access Modifier in C# The private access modifier restrict the member variable or function to be called outside of the parent class. A private function or variable cannot be called outside of the same class. It hides its member variable and method from other class and methods. public class Vehicle { private string Name; public void Color() { Console.WriteLine("Vehicle color red"); } } In the above example, you cannot call name variable outside the class because it is declared as private. 3. Protected

What is the sealed class in C#

In this article, we will learn about the sealed class and method in C#. C# Sealed Class A sealed class, in C#, is a class that cannot be inherited by any class but can be initiated. When we don't want a class can be inherited by another class, We can declare that class as sealed class. A sealed class cannot have a derived class. We use the sealed keyword to create a sealed class. sealed class Vehicle { } class Car : Vehicle { } class Program { public static void Main(string[] args) { Car car = new Car(); Console.ReadLine(); } } In the above example, we have created a sealed class Vehicle and then we are trying to derived Car class from the Vehicle class. when we are trying to compile code it'll give following errors.       C# Sealed Method When we don't want method can be override by another class, We can declare that method as sealed method. We use a sealed keyword with an overridden method to create a sealed method. class Vehicle

jQuery Selectors

How to find elements from HTML using jQuery In this article, you will learn about jQuery selectors and how to find DOM element(s) using selectors. The jQuery selector provides functionality to find DOM elements in your web page. jQuery selectors are one of the most important parts of the jQuery library. All selectors in jQuery start with the dollar sign and parentheses: $(). jQuery Selector Syntax $(selector expression) Example 1 : The .class Selector The jQuery .class selector allow you to finds all the elements with a specific class. If you want to find all the elements with class name "post-title" then the syntax will be as following. $(".post-title")   Example 2 : The #Id Selector The jQuery #Id selector allow you to finds the particular element with a specific Id. The Id selector will be used when you want to find single element from web page. $(document).ready(function(){ $("#btn-hide-title").click(function(){ $(".post-title").h

JavaScript Arrow Function

In this example, you will learn about JavaScript arrow function. Arrow function is one of the features introduced in the ES6 version of JavaScript. It allows you to create functions easy way compared to regular functions. Regular Function // regular function let result = function(a, b) { return a + b; } ES6 Arrow Function // arrow function let result = (a, b) => a + b; Arrow Function Syntax The syntax of the arrow function look like is: let myFunction = (arg1, arg2, ...argN) => { statement... } Here, myFunction is the function name arg1, arg2,...argN is the argument(parameter) of the function statement... is the body of the function

JavaScript Program to Remove Specific Item From an Array

How to Remove Specific Element From An Array In this example, you will learn to write a JavaScript program that will remove a specific element from an array. Example 1 : Using For Loop Remove Element From Array function removeElementFromArray(array, n) { const newArray = []; for ( let i = 0; i < array.length; i++) { if(array[i] !== n) { newArray.push(array[i]); } } return newArray; } const elements = [1, 2, 3, 4, 5]; const result = removeElementFromArray(elements, 4); console.log(result); Output [1,2,3,5] In the above program, an element 4 is removed from an array using a for loop. Example 2 : Using Array.splice() Remove Element From Array const elements = [1, 2, 3, 4, 5]; //remove element 3 const result = elements.splice(2,1); console.log(elements); Output [1, 2, 4, 5] In the above program, an element 3 is removed from an array using a splice() method.