Skip to main content

Posts

Showing posts from April, 2016

What is the advantage of static class over class ?

.1  When we have a normal class and its methods being used very frequently in a given app, then it would speed up things if we made this class a static class with static methods. This is because there is always a cost incurred in terms of resource usage ( CPU, memory, time) EVERY TIME a normal class is instantiated, whereas for static class its only a ONE-TIME cost when static constructor is FIRST called.  2. The main advantage of Static Classes come when there is a need to use WebMethod or a webservice, so that the application can call the static method without creating an object.

Why To Use C#

Which one to use, C++ or C#?”, and many more similar questions. It is harder to provide an answer to such questions on multiple platforms and to multiple questions. That is why, I thought, why not post a blog post to cover most of the aspects of the question?  In this post I am going to cover a few of the concepts that you may want to understand to choose either language from the most widely used languages: C or C++ Java C#  (or .NET framework itself) Basically, my own preference in many cases is C#, but that depends on what I am going to build. I have been using C, C++, Java, and C # in many applications depending on their needs, depending on how they allow me to write the programs,  and depending on whether it is the suitable programming language for this type of project and application architecture. The way I do that,is just a trick which I am going to share with you in this blog post. Among these a few of the very basic things to consider are: How simple and easy it woul

C# 6

New feature No.1 in C# 6.0   1. using Static This is a new concept in C# 6.0 that allows us to use any class that is static as a namespace that is very usefull for every developer in that code file where we need to call the static methods from a static class like in a number of times we need to call many methods from Convert.ToInt32() or Console.Write(),Console.WriteLine() so we need to write the class name first then the method name every time in C# 5.0. In C# 6.0 however Microsoft announced a new behavior to our cs compiler that allows me to call all the static methods from the static class without the name of the classes because now we need to first use our static class name in starting with all the namespaces. In C# 5.0 In C# 6.0 Code in 5.0 using  System;   using  System.Collections.Generic;   using  System.Linq;   using  System.Text;   using  System.Threading.Tasks;   namespace  TestNewCSharp6   {        class  Program       {            static   void

C# @ very best

...future of C# is very bright.   In the following Channel 9 video, Microsoft’s Dustin Campbell and Mads Torgersen talk about the future of C#. Here are some of the bullet points from the video: You can write C# in any editor you want. C# is open source now C# runs on Windows, Mac, and Linux C# can be used to build Windows client apps, Windows Store apps, iOS apps, and Android aps and also used to build backend and middle-tier frameworks and libraries. C# (via Roslyn, the C# engine): Supports all IDEs and editors All the linters and analysis tools All the fixing and refactoring and code generation tools All the scripting and all the REPLs C# 7 comes with new features including tuples, record types, and pattern matching. 

Question must to read

What is the significance of the Finalize method in .NET? The .NET Garbage Collector does nearly all the clean up activity for your objects. But unmanaged resources (for example: Windows API created objects, File, Database connection objects, COM objects and so on) are outside the scope of the .NET Framework that we need to explicitly clean our resources. For these types of objects, the .NET Framework provides the "Object.Finalize" method, which can be overridden and to clean up the code for un-managed resources. Can it be put in this section? Why is it preferred to use it instead of Finalize for clean up? The problem with Finalize is that garbage collection must make two rounds to remove objects that have Finalize methods. The figure below will make things clearer regarding the two rounds of garbage collection rounds for the objects having finalized methods. Figure 1 In this scenario there are three objects, Object1, Object2 and Object3. Object2 has the Finali

Fault contract

 Use of Fault Contract in WCF   What is the use of Fault Contract? In ASP.Net, C# and VB.Net it's very simple to handle an exception just by adding the simple Try & Catch blocks. But when you talk about the WCF Service if an unexpected error occurs (like Server not responding properly and divide by zero) in a WCF Service then the exception details can be passed to the client using a Fault Contract. Fault Contract inherits from the FaultContractAttribute Class. Now we are going to implement the Fault Contract with database connectivity Step 1: Database Setup Create a table named EMPLOYEE with column names EMP_ID and EMP_NAME. We will create a service to input the user id and get the name of the employee. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [DBO].[EMPLOYEE](           [EMP_ID] [INT] NULL,           [EMP_NAME] [VARCHAR](50) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO INSERT INTO EMPLOYEE(EMP_ID,EMP_NAM