Skip to content

Commit 35739d3

Browse files
committed
C# Interview Question
some idiotic behavior make image not rendering in web page will look into future
1 parent 25a2d47 commit 35739d3

File tree

26 files changed

+1078
-0
lines changed

26 files changed

+1078
-0
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cSpell.words": [
33
"Blazor",
44
"codefrydev",
5+
"lastmod",
56
"Prashant",
67
"Webassembly"
78
]

content/blog/blazor/Giscus.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ cover:
1212
image: "cover.jpg" # image path/url
1313
alt: "Download Logo" # alt text
1414
#caption: "Optical Character Recognition" #display caption under cover
15+
tags: [ "NET", "codefrydev", "C sharp", "CFD", "blazor" ,"GisCus"]
16+
keywords: [ "NET", "codefrydev", "C sharp", "CFD","blazor" ,"GisCus"]
17+
1518
---
1619

1720
### original Script generated using GISCUS

content/blog/interview/_index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Interview Questions on C#"
3+
author: "Codefrydev"
4+
weight: 99
5+
date: 2024-08-03
6+
lastmod: 2024-10-22
7+
dateString: August 2024
8+
description: "Common Question Asked In C# Interview. Collected From Lots Of Interview I have Attended"
9+
hideMeta: true
10+
keywords: ["Interview", "CFD", "NET" ,"Tutorials","C Sharp","Basic","Codefrydev","Code Fry Dev"]
11+
---

content/blog/interview/abstract.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: "Abstract Class Interview Questions"
3+
author: "PrashantUnity"
4+
weight: 210
5+
date: 2024-08-03
6+
lastmod: 2024-10-22
7+
dateString: August 2024
8+
description: "Guide of How To Create Blog Post, Categories And Etc"
9+
#canonicalURL: "https://canonical.url/to/page"
10+
cover:
11+
image: "cover.jpg" # image path/url
12+
alt: "Download Logo" # alt text
13+
#caption: "Optical Character Recognition" display caption under cover
14+
15+
tags: [ "NET", "codefrydev", "C sharp", "CFD"]
16+
keywords: [ "NET", "codefrydev", "C sharp", "CFD"]
17+
---
18+
19+
## Abstract Class Question
20+
21+
- Can abstract class will have non abstract method
22+
> Yes Below Example
23+
24+
- Method hiding principal ( use of New KeyWord)
25+
26+
27+
```csharp
28+
public abstract class Animal
29+
{
30+
public abstract void MakeSound();
31+
public void Eat()
32+
{
33+
Console.WriteLine("Eating...");
34+
}
35+
36+
public void IsAlive()
37+
{
38+
Console.WriteLine("Yes");
39+
}
40+
public virtual void Sleep()
41+
{
42+
Console.WriteLine("Sleeping...");
43+
}
44+
}
45+
46+
public class Dog : Animal
47+
{
48+
public override void MakeSound()
49+
{
50+
Console.WriteLine("The dog barks.");
51+
}
52+
public void Bark()
53+
{
54+
Console.WriteLine("Barking...");
55+
}
56+
public new void IsAlive()
57+
{
58+
Console.WriteLine("NO");
59+
}
60+
public override void Sleep()
61+
{
62+
Console.WriteLine("The dog barks Sleeping.");
63+
}
64+
}
65+
class Program
66+
{
67+
static void Main(string[] args)
68+
{
69+
// Create an instance of the Dog class
70+
Dog myDog = new Dog();
71+
72+
// Call methods from the abstract class (Animal)
73+
myDog.Eat(); // Output: Eating...
74+
myDog.Sleep(); // Output: The dog barks Sleeping.
75+
}
76+
}
77+
78+
```
6.25 KB
Loading
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: "ActionResult"
3+
author: "PrashantUnity"
4+
weight: 210
5+
date: 2024-08-03
6+
lastmod: 2024-10-22
7+
dateString: August 2024
8+
description: "ActionResult In Action"
9+
#canonicalURL: "https://canonical.url/to/page"
10+
cover:
11+
image: "cover.jpg" # image path/url
12+
alt: "Download Logo" # alt text
13+
#caption: "Optical Character Recognition" display caption under cover
14+
15+
tags: [ "NET", "codefrydev", "C sharp", "CFD"]
16+
keywords: [ "NET", "codefrydev", "C sharp", "CFD"]
17+
---
18+
19+
20+
## What is the difference between ‘ViewResult’ and ‘ActionResult’?
21+
22+
In ASP.NET MVC, both `ViewResult` and `ActionResult` are classes that represent the result of an action method. The primary difference between them lies in their level of abstraction.
23+
24+
1. **ActionResult:**
25+
> `ActionResult` is the base class for all action results in ASP.NET MVC. It provides a high level of abstraction, allowing action methods to return various types of results, such as `ViewResult`, `RedirectResult`, `JsonResult`, etc.
26+
27+
> When we define an action method, we can use `ActionResult` as the return type, providing flexibility to return different types of results based on the specific requirements of our action.
28+
29+
> Example:
30+
31+
```csharp
32+
public ActionResult MyAction()
33+
{
34+
// ... logic ...
35+
return View(); // Returning a ViewResult
36+
}
37+
```
38+
39+
2. **ViewResult:**
40+
> `ViewResult` is a derived class of `ActionResult` specifically designed for returning a view from an action method. It represents the result of rendering a view.
41+
42+
> When we want an action method to render a view, we can use `ViewResult` as the return type. This class allows we to set properties related to the view, such as the view name, model, and view data.
43+
44+
> Example:
45+
46+
```csharp
47+
public ViewResult MyViewAction()
48+
{
49+
// ... logic ...
50+
return View("MyView", myModel); // Returning a ViewResult with view name and model
51+
}
52+
```
53+
54+
> `ActionResult` is a more general type that allows we to return various types of results.
55+
56+
> `ViewResult` provides a bit more clarity in our code when we specifically want to indicate that our action method is rendering a view.
6.66 KB
Loading

content/blog/interview/adonet.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "Ado Net"
3+
author: "PrashantUnity"
4+
weight: 210
5+
date: 2024-08-03
6+
lastmod: 2024-10-22
7+
dateString: August 2024
8+
description: "Ado Net To Connect ith Database"
9+
#canonicalURL: "https://canonical.url/to/page"
10+
cover:
11+
image: "cover.jpg" # image path/url
12+
alt: "Download Logo" # alt text
13+
#caption: "Optical Character Recognition" display caption under cover
14+
15+
tags: [ "NET", "codefrydev", "C sharp", "CFD","adonet"]
16+
keywords: [ "NET", "codefrydev", "C sharp", "CFD","adonet"]
17+
---
18+
19+
### 1. What is ADO.NET?
20+
21+
ADO.NET (ActiveX Data Objects) is a data access technology in the .NET framework used to interact with data sources, such as databases. It provides a set of classes for connecting to databases, executing commands (queries, updates), and retrieving results into datasets or data readers.
22+
23+
### 2. Differentiate between DataSet and DataReader
24+
25+
- **DataSet:** It's an in-memory cache of data retrieved from the database. It can hold multiple DataTables, relationships, and constraints. It is disconnected, meaning it doesn't need an active connection to the database once data is loaded.
26+
- **DataReader:** It provides a read-only, forward-only stream of data from the database. It's faster and uses less memory compared to DataSet but is less flexible as it doesn't store data locally.
27+
28+
### 3. Explain the steps to connect to a database using ADO.NET
29+
30+
To connect to a database using ADO.NET:
31+
32+
- Create a connection object (`SqlConnection`, `OleDbConnection`, etc.).
33+
- Open the connection using `Open()` method.
34+
- Create a command object (`SqlCommand`, `OleDbCommand`, etc.) specifying the SQL query or stored procedure.
35+
- Execute the command using `ExecuteNonQuery()`, `ExecuteScalar()`, or `ExecuteReader()` methods.
36+
- Close the connection using the `Close()` or `Dispose()` method.
37+
38+
### 4. What are the different components of ADO.NET?
39+
40+
ADO.NET consists of several key components:
41+
42+
- **Connection:** Represents a connection to a data source.
43+
- **Command:** Executes commands (SQL queries or stored procedures) against a database.
44+
- **DataReader:** Retrieves data in a read-only, forward-only manner.
45+
- **DataAdapter:** Populates a DataSet and resolves changes back to the database.
46+
- **DataSet:** In-memory cache holding data in tables and relationships.
47+
48+
### 5. How does ADO.NET prevent SQL injection attacks?
49+
50+
ADO.NET provides parameterized queries through `SqlParameter` objects. Using parameterized queries ensures that input values are treated as parameters rather than concatenated directly into the SQL command. This prevents malicious SQL injection by separating data from SQL commands.
51+
52+
### 6. Explain the difference between SqlCommand and SqlDataAdapter
53+
54+
- **SqlCommand:** Represents a SQL command to be executed against a database. It's used to execute SQL queries, stored procedures, and perform data manipulation operations.
55+
- **SqlDataAdapter:** Acts as a bridge between a DataSet and a data source. It populates the DataSet and resolves changes back to the database using `Fill()` and `Update()` methods.
56+
57+
### 7. What is the purpose of the ExecuteNonQuery() method in ADO.NET?
58+
59+
`ExecuteNonQuery()` method is used to execute SQL commands (such as INSERT, UPDATE, DELETE) that don't return any data, only the number of rows affected by the command.
60+
61+
### 8. How can you handle exceptions in ADO.NET?
62+
63+
Exceptions in ADO.NET can be handled using `try-catch` blocks. Commonly used exception classes are `SqlException`, `OleDbException`, etc. Handling exceptions involves catching specific exceptions that may occur during database operations and taking appropriate actions, such as logging errors or displaying user-friendly messages.
6.12 KB
Loading

content/blog/interview/assembly.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: "What is Assembly ?"
3+
author: "PrashantUnity"
4+
weight: 210
5+
date: 2024-08-03
6+
lastmod: 2024-10-22
7+
dateString: August 2024
8+
description: "About Assembly"
9+
#canonicalURL: "https://canonical.url/to/page"
10+
cover:
11+
image: "cover.jpg" # image path/url
12+
alt: "Download Logo" # alt text
13+
#caption: "Optical Character Recognition" display caption under cover
14+
15+
tags: [ "NET", "codefrydev", "C sharp", "CFD", "assembly","Interview"]
16+
keywords: [ "NET", "codefrydev", "C sharp", "CFD","Interview"]
17+
---
18+
19+
## Simple Form
20+
21+
- Assembly is unit of deployment like EXE or a DLL
22+
- When you create a code and build the solution, then the .NET
23+
Framework convert your code into Intermediate Language and
24+
that is placed inside the assembly(dll), which you can find
25+
inside bin folder
26+
27+
- **Assembly:** A compiled code library in .NET that contains types, resources, and metadata.
28+
- **Types of Assemblies:** Executable (EXE) and Library (DLL).
29+
- **Components:** Manifest, metadata, IL code, and resources.
30+
- **Strong Naming:** Ensures assembly uniqueness and integrity.
31+
- **Global Assembly Cache (GAC):** Stores shared assemblies across applications.
6.35 KB
Loading

content/blog/interview/classacess.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
title: "Class Access Level"
3+
author: "PrashantUnity"
4+
weight: 210
5+
date: 2024-08-03
6+
lastmod: 2024-10-22
7+
dateString: August 2024
8+
description: "In C#, the accessibility level of a class determines how and where the class can be accessed from other parts of your code."
9+
#canonicalURL: "https://canonical.url/to/page"
10+
cover:
11+
image: "cover.jpg" # image path/url
12+
alt: "Download Logo" # alt text
13+
#caption: "Optical Character Recognition" display caption under cover
14+
15+
tags: [ "NET", "codefrydev", "C sharp", "CFD"]
16+
keywords: [ "NET", "codefrydev", "C sharp", "CFD"]
17+
---
18+
19+
20+
# Class Accessibility Matrix Diagram
21+
22+
![Accessibility](./acess.png)
23+
24+
25+
## What is Default accessibility of class
26+
27+
- Internal
28+
29+
## Difference between Internal and Protected Internal
30+
31+
- Look above image for clarification
32+
33+
### 1. **Public**
34+
35+
- **Accessibility:** The class is accessible from any other class or assembly.
36+
- **Usage:** When you want the class to be widely accessible.
37+
38+
```csharp
39+
// Public class can be accessed from anywhere
40+
public class PublicClass
41+
{
42+
public string Name { get; set; }
43+
}
44+
```
45+
46+
### 2. **Internal**
47+
48+
- **Accessibility:** The class is accessible only within the same assembly (project).
49+
- **Usage:** When you want to limit access to within the assembly, which is useful for encapsulation.
50+
51+
```csharp
52+
// Internal class can only be accessed within the same assembly
53+
internal class InternalClass
54+
{
55+
public string Name { get; set; }
56+
}
57+
```
58+
59+
### 3. **Protected**
60+
61+
- **Accessibility:** The class itself cannot be protected, but its members can be. A class can be derived from a base class with protected members.
62+
- **Usage:** When you want to allow access to members only in derived classes.
63+
64+
```csharp
65+
public class BaseClass
66+
{
67+
protected string Name { get; set; }
68+
}
69+
70+
public class DerivedClass : BaseClass
71+
{
72+
public void PrintName()
73+
{
74+
// Accessing protected member from the base class
75+
Console.WriteLine(Name);
76+
}
77+
}
78+
```
79+
80+
### 4. **Private**
81+
82+
- **Accessibility:** A class itself cannot be private, but its members can be. Private members are only accessible within the same class.
83+
- **Usage:** When you want to restrict access to the class members to only within the class itself.
84+
85+
```csharp
86+
public class MyClass
87+
{
88+
private string Name { get; set; }
89+
90+
public void SetName(string name)
91+
{
92+
Name = name;
93+
}
94+
95+
public string GetName()
96+
{
97+
return Name;
98+
}
99+
}
100+
```
101+
102+
### 5. **Protected Internal**
103+
104+
- **Accessibility:** The class or member is accessible within the same assembly and also to derived classes in other assemblies.
105+
- **Usage:** Useful for situations where you want to expose class members to derived classes or within the assembly.
106+
107+
```csharp
108+
public class MyClass
109+
{
110+
protected internal string Name { get; set; }
111+
}
112+
```
113+
114+
### 6. **Private Protected**
115+
116+
- **Accessibility:** The class or member is accessible within the same class or in derived classes that are in the same assembly.
117+
- **Usage:** A more restrictive version of `protected internal`, useful for fine-grained access control.
118+
119+
```csharp
120+
public class MyClass
121+
{
122+
private protected string Name { get; set; }
123+
}
124+
```
1.23 MB
Loading
6.64 KB
Loading

0 commit comments

Comments
 (0)