Thursday 19 August 2021

C# Question and answers

 --Type of serializations and the fastest serialization in c#

--List down the caches you have used, and name 2 distributed caching

--How to perform memory optimizations in C#. Name 2 incidents

--Lazy loading

--what are middleware’s in c# and how to create them

--Difference between SAML and ws-federation protocol in authentication

--How to create test certificates during development, and name the tools you have used

--Difference between symmetric and asymmetric algorithm

--What are the databases you have used?

--How to connect MongoDB database from C# code? Please name the C# driver you have used for this

=============================================================


1.The binary serializer included with .net should be faster that the XmlSerializer. Or another serializer for protobuf, json, ...

But for some of them you need to add Attributes, or some other way to add metadata. For example ProtoBuf uses numeric property IDs internally, and the mapping needs to be somehow conserved by a different mechanism. Versioning isn't trivial with any serializer.

2.This is being primarily used in the industries today, for having the potential to scale on demand & being highly available.

(A). Scalability, High Availability, Fault-tolerance are crucial to the large scale services running online today.
(B). Businesses cannot afford to have their services go offline. Think about health services, stock markets, military. They have no scope for going down. They are distributed across multiple nodes with a pretty solid amount of redundancy.
 Google Cloud uses Memcache for caching data on its public cloud platform. 2.b. OutputCache filter 2.c.Data Caching3.d.Fragment Caching.

3.Dispose an object after use or make it null.

Use try/finally or using block.
Use GC. Collect() if required.
Remove unnecessary object initialization.
Manage Image caching.
Mange BLOB data, Memory stream and file stream.

4.Lazy loading is essential when the cost of object creation is very high and the use of the object is vey rare. So, this is the scenario where it's worth implementing lazy loading.
The fundamental idea of lazy loading is to load object/data when needed.
5.Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:
Chooses whether to pass the request to the next component in the pipeline.
Can perform work before and after the next component in the pipeline.
Request delegates are used to build the request pipeline. The request delegates handle each HTTP request.
Request delegates are configured using Run, Map, and Use extension methods. An individual request delegate can be specified in-line as an anonymous method (called in-line middleware), or it can be defined in a reusable class. These reusable classes and in-line anonymous methods are middleware, also called middleware components. Each middleware component in the request pipeline is responsible for invoking the next component in the pipeline or short-circuiting the pipeline. When a middleware short-circuits, it's called a terminal middleware because it prevents further middleware from processing the request.
6.WS-Federation is primarily championed by Microsoft Corporation which has invested heavily into incorporating WS-Federation into its products. SAML is an older specification that is well supported by many identity management vendors. However, most vendors, including Microsoft, are moving to support both standards.
7.Test-signing requires a test certificate. After a test certificate is generated, it can be used to test-sign multiple drivers or driver packages. For more information, see Test Certificates.

This topic describes how to use the MakeCert tool to create test certificates. In most development environments, test certificates generated through MakeCert should be sufficient to test the installation and loading of test-signed drivers or driver packages. For more information about this type of test certificate.
8.Symmetric Key Encryption:
Encryption is a process to change the form of any message in order to protect it from reading by anyone. In Symmetric-key encryption the message is encrypted by using a key and the same key is used to decrypt the message which makes it easy to use but less secure. It also requires a safe method to transfer the key from one party to another.

Asymmetric Key Encryption:
Asymmetric Key Encryption is based on public and private key encryption technique. It uses two different key to encrypt and decrypt the message. It is more secure than symmetric key encryption technique but is much slower.
9. SqlS erver, Oracle, Sybase,MySql. Azure Sql, Blob Storage, MongoDB

10.using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Timers;  
using MongoDB.Bson;  
using MongoDB.Driver;  
using MongoDB.Driver.Builders;  
using MongoDB.Driver.GridFS;  
using MongoDB.Driver.Linq;  
using System.Data.SqlClient;  
namespace MongodbRND  
{  
   class Program  
   {  
      static void Main(string[] args)  
      {  
         Console.WriteLine("Mongo DB Test Application");  
         Console.WriteLine("====================================================");  
         Console.WriteLine("Started By:Kailash Chandra Behera");  
         Console.WriteLine("Started On: 14 July 2014");  
         Console.WriteLine("Configuration Setting: 172.16.1.24:27017");  
         Console.WriteLine("====================================================");  
         Console.WriteLine("Initializaing connection");  
         string connectionString = "mongodb://172.16.1.24:27017";  
 
 
         Console.WriteLine("Creating Client..........");  
         MongoClient client = null;  
         try  
         {  
            client = new MongoClient(connectionString);  
            Console.WriteLine("Client Created Successfuly........");  
            Console.WriteLine("Client: " + client.ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Filed to Create Client.......");  
            Console.WriteLine(ex.Message);  
         }  
 
         Console.WriteLine("Initianting Mongo Db Server.......");  
         MongoServer server = null;  
         try  
         {  
            Console.WriteLine("Getting Servicer object......");  
            server = client.GetServer();  
 
            Console.WriteLine("Server object created Successfully....");  
            Console.WriteLine("Server :" + server.ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Filed to getting Server Details");  
            Console.WriteLine(ex.Message);  
         }  
 
 
         Console.WriteLine("Initianting Mongo Databaser.........");  
         MongoDatabase database = null;  
         try  
         {  
            Console.WriteLine("Getting reference of database.......");  
            database = server.GetDatabase("Kailash");  
            Console.WriteLine("Database Name : " + database.Name);  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to Get reference of Database");  
            Console.WriteLine("Error :" + ex.Message);  
         }  
         try  
         {  
            Console.WriteLine("Deleteing Collection Symbol");  
            database.DropCollection("Symbol");  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to delete collection from Database");  
            Console.WriteLine("Error :" + ex.Message);  
         }  
 
         Console.WriteLine("Getting Collections from database Database.......");  
 
 
         MongoCollection symbolcollection = null;  
         try  
         {  
            symbolcollection = database.GetCollection<Symbol>("Symbols");  
            Console.WriteLine(symbolcollection.Count().ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to Get collection from Database");  
            Console.WriteLine("Error :" + ex.Message);  
         }  
         ObjectId id = new ObjectId();  
         Console.WriteLine("Inserting document to collection............");  
         try  
         {  
            Symbol symbol = new Symbol ();  
            symbol.Name = “Star”;  
            symbolcollection.Insert(symbol);  
            id = symbol.ID;  
 
            Symbol symbol = new Symbol ();  
            symbol.Name = “Star1”;  
            symbolcollection.Insert(symbol);  
            id = symbol.ID;  
 
            Console.WriteLine(symbolcollection.Count().ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to insert into collection of Database " + database.Name);  
            Console.WriteLine("Error :" + ex.Message);  
         }  
 
         try  
         {  
            Console.WriteLine("Preparing Query Document............");  
            List< Symbol > query = symbolcollection.AsQueryable<Entity>().Where<Entity>(sb => sb.Name == "Kailash").ToList();  
 
            Symbol symbol = symbolcollection.AsQueryable<Entity>().Where<Entity>(sb => sb. ID == id).ToList();  
 
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to query from collection");  
            Console.WriteLine("Exception :" + ex.Message);  
         }  
         Console.WriteLine("");  
         Console.WriteLine("====================================================");  
         Console.ReadLine();  
      }  
   }  
   public class Symbol  
   {  
      public string Name { get; set; }  
      public ObjectId ID { get; set; }  
   }  

No comments:

Post a Comment