//Word duplication checking
string s = "eearr";
string duplicatewords=string.Empty;
for (int i = 0; i < s.Length; i++)
{
if (!(duplicatewords.Contains(s[i].ToString())))
{
duplicatewords += s[i];
}
}
Console.WriteLine(duplicatewords);
Output:
//Word duplication checking
string s = "eearr";
string duplicatewords=string.Empty;
for (int i = 0; i < s.Length; i++)
{
if (!(duplicatewords.Contains(s[i].ToString())))
{
duplicatewords += s[i];
}
}
Console.WriteLine(duplicatewords);
Output:
What is JWT?
JSON Web Token (JWT) serves as a compact and self-contained mechanism for securely transmitting information between parties as a JSON object.
JWT Structure/Components:
Header: Specifies the token type (JWT) and the signing algorithm (e.g., HMAC SHA256).
Payload: Contains the claims, which are statements about an entity (user) and additional metadata.
Signature: Created by encoding the header and payload with a secret, ensuring the token’s integrity.
JWT in Action:
Advantages:
Scalability: Due to their stateless nature, JWTs are ideal for distributed systems.
Flexibility: They can be used across different domains and applications.
Security: When properly implemented, they provide a secure way to handle user authentication.
Security Concerns:
Transmission Security: It's vital to transmit JWTs over HTTPS.
Storage: Store JWTs securely to prevent XSS attacks and other vulnerabilities.
Handling Token Expiry:
Implement short-lived JWTs and use refresh tokens for renewing access without re-authentication.
Interface Class
interface InterfaceA
{
string MethodA(string s);
}
Abstract Class
public class AbstractB:InterfaceA
{
public string MethodA(string s)
{
return s;
}
}
Object Creation Using Abstract
AbstractB abstractB = new AbstractB();
abstractB.MethodA("Abstract object");
Output : Abstract object
Object Creation Using Interface
InterfaceA interfaceA = new AbstractB();
interfaceA.MethodA("Interface object");
Output : Interface object
Note (Object Creation Using Interface) :
PROPS |
STATE |
The
Data is passed from one component to another. |
The
Data is passed within the component only. |
It is
Immutable (cannot be modified). |
It is
Mutable ( can be modified). |
Props
can be used with state and functional components. |
The
state can be used only with the state components/class component (Before
16.0). |
Props
are read-only. |
The
state is both read and write. |
We use the shouldComponentUpdate() Lifecycle method to customize the default behavior and implement it when the React component should re-render or update itself.
import React from "react";
export default class Test extends React.PureComponent {
render() {
return <h1>Welcome to GeeksforGeeks</h1>;
}
}
Pure components automatically implement the shouldComponentUpdate() method with a shallow prop and state comparison. This method returns false if the props and state haven’t changed.
how to handle fallback content while asynchronous actions are pending and encapsulate any portion of your component tree
<Suspense fallback={<LeoFallback />}>
<LeoComponent />
</Suspense>
First, import the Suspense components from React, as well as any components you intend to load lazily.
import { Suspense } from 'react';
Then use lazy() to define a dynamic import. For the component you wish to load slowly, this function accepts an argument that is a function that produces a dynamic import statement.
const LeoComponent = lazy(() => import('./LeoComponent'));
Prop Drilling - Passing the props from parent to Child or nested child for multiple components is props drilling
Coding Example :
Syntax : useEffect(<function>, <dependency>)
1.No dependency passed - Runs on every render:
useEffect(() => {
//Runs on every render
});
Output Times Increase automatically :2.Empty Array in dependency - Runs only on the first render:
useEffect(() => {
//Runs only on the first render
}, []);
After adding Empty Array in Dependency
3. Props or state values - Runs on the first render And any time any dependency value changes
useEffect(() => {
//Runs on the first render
//And any time any dependency value changes
}, [prop, state]);
Adding State dependency in the Array :
4. Effect Cleanup - Some effects require cleanup to reduce memory leaks
UseEffect(() =>{let timer = setTimeout(() => {}); return () => clearTimeout(timer)},[])
After adding cleanup : first time its rendered , once then it have been cleaned up
Linq provides us following Element operators
• First
• FirstOrDefault
• Last
• LastOrDefault
• ElementAt
• ElementAtOrDefault
• Single
• SingleOrDefault
• DefaultIfEmpty
Entity Framework is an Object relation Management (ORM) from Microsoft
ADO.NET Vs Entity Framework
ADO.NET |
Entity Framework |
Ado.net is faster |
EF will be
around the ADO.net which means ADO.NET is faster then EF |
We need to write
so much code to talk to database |
Easy to use. As an EF will
talk to database without much code involved |
Performance
is better than EF |
Performance
is not good compared to ADO.NET |
Linq to SQL Vs Entity Framework
LINQ to SQL |
Entity Framework |
Supports only
for SQL database |
Supports
database like SQL,Mysql,DB2 etc. |
Allows only
one to one mapping between the entity classes and the relational table |
Allows one to
one , one to many & many to many mappings between the entity classes and
the relational tables |
.dbml file is
generated for maintaining the relationship |
Relationships
are maintained in 3 different files .csdl,.msl and .ssdl |
Lifecycle of Components
Mounting
Updating
Unmounting
Code which managed(C#) by CLR is managed Code.
Code which does not managed(c++,VB6 code) by CLR then its unmanaged code.
Garbage collector will not destroy the object which are created out side of the CLR.
UserState
The React useState Hook allows us to track state in a function component.
State generally refers to data or properties that need to be tracking in an application.
UserState with Single State:
Code:
Output:
After Button Click Output:
UserState with Object State:
Code:
Output:
After Button Click Output:
Types of React Hooks:
1.UserState
C#
1. String Vs String builder
String |
String Builder |
Inmutable(unable
to be changed.) |
Mutable |
Object
reacted for each string object separately in memory and it will create plenty
of memory so it may be run slow |
Use less
memory and run faster |
2. Read-only Vs Const Vs Static
3. Abstract Vs Interface
4. Ref Vs Out
Ref |
Out |
|
|
5. For Vs Foreach
Default Constructor:
public Person()
{
Name = "John Doe";
Age = 30;
}
Parameterized Constructor:
Scholar(String name, int id)
{
this.name = name;
this.id = id;
}
Copy Constructor:
class Scholars
{
private string month;
private int year;
// Declaring Copy constructor
public Scholars(Scholars s)
{
month = s.month;
year = s.year;
}
// Instance constructor
public Scholars(string month, int year)
{
this.month = month;
this.year = year;
}
}
Private Constructor:
A constructor is referred to as a private constructor if it was created with the private specifier. This class cannot be derived from by any other classes, nor can an instance of this class be created.
public class Scholars
{
// Declare a private constructor
private Scholars()
{
}
// Declare a static variable field
public static int count_scholars;
// Declare a static method
public static int scholars_Count()
{
return ++count_scholars;
}
}
Static Constructor:
Static constructors are designed to be used just once to initialize static class fields or data.
class scholars {
// It is invoked before the first
// instance constructor is run.
static scholars()
{
// The following statement produces
// the first line of output,
// and the line occurs only once.
Console.WriteLine("Static Constructor");
}
}
7. SOLID Principle
8. Delegate with Example
9. Type of Routing
Conventional Routing and Attributal Routing
10. Sealed Class Vs Static Class
11. MVC filter
After MVC 5 Authentication filter is also available
12. Action Results
13. Tempdata - Peek Vs Keep
14. As Vs Is
15. Extenstion Methods
16. Overloading (Compile-Time) Vs Overrding(Run-Time)
17.Generic Collections(Array, IDictory,List ,IList)
Generic is a type to be specified later. They are instantiated when needed for a specific type provided as parameters. In other words, a Generic allows you to write a class or method that can work with any data type(System.Collection.Generic namespace)
18. Icollections Vs IEnumerable
19. DI Life Time and DI in .NET core
20. CORS
21. React Hook
22. React Life Cycle
23. Thirdparty React - Router, Redux , Axios
24. SQL Optimization (Exection Plan tab check ,etc.)
25. Handle Error
.NET using log4net Vs .NET Core Serilogger
26. Struc Vs Class
Console.WriteLine("Enter Word reversing: ");
string s1=Console.ReadLine();
string s2= string.Empty;
for (int i = s1.Length -1; i > -1; i--)
{
s2 += s1[i].ToString();
}
Console.WriteLine(s2);
OUTPUT
Console.WriteLine("Enter First word: ");
string s1 = Console.ReadLine();
Console.WriteLine("Enter Second word: ");
string s2 = Console.ReadLine();
int j = 0;
for (int i = 0; i < s2.Length; i++)
{
s1.Contains(s1[i]);
j++;
}
string s3 = j == s1.Length ? "Word in First word is also present in the second" : "Word in First word is not present in the second";
Console.WriteLine(s3);
Types of Deadlock
exclusive lock(X), shared lock(S), update lock (U), intent lock (I), schema lock (SCH) and bulk update lock (BU)
select * from sys.dm_tran_locks
The first time a user sees the following message, the result of an unhandled deadlock error in SQL Server, it can come as quite a shock.
Msg 1205, Level 13, State 56, Line 10
Transaction (Process ID 62) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
Two or more sessions were waiting to acquire a lock on a resource already locked by another session in the same locking chain. The result is a 'circular chain' where no session can complete, and so SQL Server is forced to intervene to clear up the mess. It automatically chooses one of the sessions as the 'victim', kills it and rolls back its transaction. It means that the other sessions may proceed, but that is little comfort to the hapless victim, and if that victim happens to be a session running a critical business process, then it may soon be of little comfort to the DBA.
React Redux 8.x requires React 16.8.3 or later / React Native 0.59 or later, in order to make use of React Hooks.
React Redux includes a <Provider />
component, which makes the Redux store available to the rest of your app:
import React from 'react'
import ReactDOM from 'react-dom/client'
import { Provider } from 'react-redux'
import store from './store'
import App from './App'
// As of React 18
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
<Provider store={store}>
<App />
</Provider>,
)
useSelector
reads a value from the store state and subscribes to updates, while useDispatch
returns the store's dispatch
method to let you dispatch actions.
import React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import {
decrement,
increment,
incrementByAmount,
incrementAsync,
selectCount,
} from './counterSlice'
import styles from './Counter.module.css'
export function Counter() {
const count = useSelector(selectCount)
const dispatch = useDispatch()
return (
<div>
<div className={styles.row}>
<button
className={styles.button}
aria-label="Increment value"
onClick={() => dispatch(increment())}
>
+
</button>
<span className={styles.value}>{count}</span>
<button
className={styles.button}
aria-label="Decrement value"
onClick={() => dispatch(decrement())}
>
-
</button>
</div>
{/* omit additional rendering output here */}
</div>
)
}