Okumak ve incelemek için harika şeyler bulmanıza ve harika içerikler üreterek dünya ile paylaşmanıza yardımcı olacağız.
Looking to ace your next CSharp interview or simply boost your coding prowess? You’ve come to the right place! This blog is packed with 100 carefully curated C# programming questions and answers, designed to help both beginners and seasoned developers. From basic syntax to advanced concepts, we’ve got you covered. So, let’s dive in and start mastering C# programming!
Thread.Sleep(0) signals the operating system that the current thread’s time slice is finished and it can switch to another thread.
Foreground threads keep an application alive until all foreground threads are completed. Background threads are terminated automatically when the application closes.
ParameterizedThreadStart allows passing data to the thread start method. For example: Thread t = new Thread(new ParameterizedThreadStart(ThreadMethod)); t.Start(5);
ThreadAbortException occurs when a thread is stopped using the Thread.Abort method.
ThreadStaticAttribute ensures each thread has its own copy of a field. For example: [ThreadStatic] public static int _field;
ThreadLocal is used to create and initialize local data for each thread. For example: public static ThreadLocal _field = new ThreadLocal(() => { return Thread.CurrentThread.ManagedThreadId; });
A thread pool reuses threads to manage resources efficiently. Threads are not killed after completion but reused.
The Task class represents some work to be done. It can tell if the work is completed and if it returns a result. For example: Task t = Task.Run(() => { for (int x = 0; x < 100; x++) { Console.Write(‘*’); } }); t.Wait();
Task allows a task to return a value. For example: Task t = Task.Run(() => { return 42; }); Console.WriteLine(t.Result);
Task.WaitAll waits for multiple tasks to complete before proceeding. For example: Task.WaitAll(tasks);
Task.WaitAny waits until any one of the tasks is completed. For example: int i = Task.WaitAny(tasks);
The Parallel class is used to execute tasks in parallel. For example: Parallel.For(0, 10, i => { Thread.Sleep(1000); });
ParallelLoopState provides functionalities to stop or break a parallel loop. For example: loopState.Break();
async and await simplify writing asynchronous code in C#. For example: public async Task DownloadContent() { string result = await client.GetStringAsync(url); return result; }
PLINQ is used to execute LINQ queries in parallel. For example: var parallelResult = numbers.AsParallel().Where(i => i % 2 == 0).ToArray();
SynchronizationContext abstracts the application model’s threading model, ensuring code runs on the correct thread for UI updates or web request processing.
ConfigureAwait(false) ensures the code after an await does not run on the UI thread, improving performance.
Fire-and-forget is an asynchronous method where the result or exceptions cannot be inspected. It should only be used for asynchronous event handlers.
Types ensure data and functionalities are organized and reusable.
class ClassName { // Fields and methods }
Generics allow creating classes and methods that work with any data type. For example: List
Type conversion changes data from one type to another. For example: int num = int.Parse(“123”);
Boxing converts a value type to an object type. Unboxing converts the object back to the value type. For example: object obj = 123; int num = (int)obj;
Dynamic types are checked at runtime. For example: dynamic dyn = “Hello”; dyn = 123;
public, private, protected, and internal control the visibility of class members.
Properties provide controlled access to class members. For example: public int MyProperty { get; set; }
Interfaces define methods that classes must implement. For example: interface IMyInterface { void MyMethod(); }
Inheritance allows a class to inherit features from another class. For example: class DerivedClass : BaseClass { }
An abstract class cannot be instantiated and contains at least one abstract method. For example: abstract class MyBaseClass { public abstract void MyMethod(); }
A static class cannot be instantiated and only contains static members. For example: static class MyStaticClass { public static void MyMethod() { } }
Nested classes are defined within another class. For example: class OuterClass { class InnerClass { } }
Reflection provides access to metadata about types at runtime. For example: Type type = typeof(MyClass);
CodeDom and lambda expressions are used to dynamically generate code.
Garbage collection automates memory management by cleaning up unused objects.
Unmanaged resources are not automatically handled by the garbage collector and are managed using the IDisposable interface.
String manipulation involves performing operations on strings. For example: string.Concat(“Hello”, “World”);
String searching uses methods like IndexOf and Contains. For example: string s = “Hello”; bool contains = s.Contains(“H”);
String formatting specifies how strings should be represented. For example: string.Format(“Number: {0}”, 123);
Input validation ensures user inputs are secure and correct, maintaining data integrity and preventing security vulnerabilities.
Data integrity is maintained using input validation, type conversions, and regular expressions.
These methods convert strings and other data types to other types. For example: int.TryParse(“123”, out int result);
Regular expressions are used for pattern matching and text manipulation. For example: Regex.IsMatch(“123″, @”^\d+$”);
JSON and XML validation is performed using schemas and custom validation methods.
Symmetric encryption uses the same key for encryption and decryption, while asymmetric encryption uses different keys.
The .NET Framework uses classes like Aes and RSA for encryption. For example: Aes.Create();
Hashing creates a fixed-size hash of data. For example: SHA256.Create().ComputeHash(data);
Certificates are used for security and authentication. For example: X509Certificate2(certPath);
Code access permissions control which resources code can access. For example: FileIOPermission
Securing string data involves encryption and other security measures.
Assemblies are compiled code files containing program components.
The Global Assembly Cache (GAC) stores shared assemblies. For example: gacutil -i myAssembly.dll
Assembly versioning manages different versions of assemblies. For example: [assembly: AssemblyVersion(“1.0.0.0”)]
WinMD files define Windows Runtime components.
Debugging finds and fixes application errors using tools like Visual Studio debuggers.
Compiler directives instruct the compiler on how to process code under specific conditions. For example: #define DEBUG
Program Database (PDB) files contain debugging information for compiled programs.
Logging and tracing record significant events during application execution.
Performance counters monitor system and application performance. For example: PerformanceCounter
I/O operations are performed by working with files and streams. For example: File.ReadAllText(“path”);
Streams are data channels for reading or writing data. For example: FileStream
Communication over the network uses classes like HttpClient and TcpClient.
Database operations are performed using ADO.NET or Entity Framework.
Web services are consumed using HttpClient or WCF.
XML documents are processed using XmlDocument or XDocument.
JSON data is processed using JsonConvert or System.Text.Json.
LINQ allows querying data collections. For example: var query = from num in numbers where num > 5 select num;
LINQ queries perform criteria-based operations on data sources.
Serialization converts an object to a data stream. For example: XmlSerializer
XML serialization is done using XmlSerializer to serialize objects to XML format.
Binary serialization converts objects to binary format.
DataContract defines a data contract, often used with WCF.
JSON serialization is done using JsonSerializer or JsonConvert.
Data is stored and retrieved using arrays, lists, dictionaries, etc.
Generic collections work with a specific data type, while nongeneric collections work with any data type.
List stores a collection of elements of a specific type. For example: List numbers = new List();
Dictionary stores key-value pairs. For example: Dictionary ages = new Dictionary();
HashSet stores unique elements. For example: HashSet uniqueNumbers = new HashSet();
Queue operates in FIFO (First-In-First-Out) order. Stack operates in LIFO (Last-In-First-Out) order.
A custom collection class is created to represent a specific data structure.
Asynchronous reading and writing operations are done using classes like FileStream.
Entity Framework simplifies database operations using an ORM. For example: context.SaveChanges();
RESTful web services are consumed using HttpClient.
GraphQL allows querying and updating APIs. Libraries like GraphQL.Client can be used.
Blazor is a framework for building web applications using .NET. It uses C# and Razor to create web applications.
Xamarin is a framework for building mobile applications using .NET. It allows creating Android and iOS apps using C#.
UWP allows developing applications for Windows 10 devices using XAML and C#.
WPF is a framework for building desktop applications using XAML and C#.
Windows Forms is a framework for building desktop applications for Windows using form controls.
ASP.NET Core is a framework for building web applications using MVC, Razor Pages, and Web API.
SignalR is a library for building real-time web applications. It uses WebSocket and other technologies for real-time data communication.
Azure Functions are event-driven, serverless functions that can be created using C#.
Microservices are small, independent services that make up an application. They can be deployed using technologies like Docker and Kubernetes.
CI/CD automates the integration and deployment processes. Tools like Azure DevOps or GitHub Actions can be used.
Dependency Injection manages and injects object dependencies. It is commonly used in frameworks like ASP.NET Core.
Unit testing tests small units of code. Frameworks like xUnit, NUnit, or MSTest are used.
Integration testing tests the interaction between components. It can be done using test servers or mock services.
Performance testing measures the application’s speed and performance. Tools like JMeter or Visual Studio Load Test can be used.
Security testing identifies vulnerabilities in the application. Tools like OWASP ZAP or Burp Suite can be used.
This blog post will serve as a comprehensive guide with 100 questions and answers on CSharp programming. It aims to help readers of all skill levels enhance their understanding and proficiency in C#. By covering a wide range of topics, it ensures that users can find valuable information whether they are prepping for an interview, looking to solve a specific problem, or simply brushing up on their skills. Ready to get started?