Skip to main content

Posts

Showing posts from 2014

Difference Between ref and out Keywords

=> ref causes an argument to be passed by reference not by value.  It provides a reference to the source value and changes made in the method will be made to the source object =>  Arguments passed as ref must be initialized before they are passed. =>  out also causes an argument to be passed by reference.  Changes made to the parameter are also changed in the source. =>  Arguments passed using out do not have to be initialized first. =>  The called method must assign a value prior to the method return statement

When to Use a struct vs Class, Cont’d

=> structs are value types that can contain data and functions. =>  structs are value types and do not require heap allocation. =>  structs directly store their data in the struct , classes store a reference to a dynamically allocated bject. =>  structs are useful for small data structures.  =>  structs can affect performance =>  Constructors are invoked with the new operator, but that does not allocate memory on the heap  =>  A struct constructor simply returns the struct value itself (typically in a temporary location on the stack), and this value is then copied as necessary  =>  With classes, multiple variables may have a reference to the same object  =>  It is possible for operations on one variable to affect the object referenced by the other variable. =>  With structs , the variables each have their own copy of the data, and it is not possible for operations on one to affect the other. =>  structs do not support user-

What is the Difference between String and string

=>The string type is a sealed class type that inherits directly from object. Instances of the string class represent Unicode character strings. =>  Values of the string type can be written as string literals. =>  The keyword string is simply an alias for the predefined class System.String so you can use string name = “Fred”; or String name = “Fred”;. =>  Likewise you can use string.Concat () or String.Concat () =>  Use string for variable names =>  Use S tring for class methods and reference

Identify and Delete duplicate Records in SQL Server

      S cenario: I have accumulated data into SQL Server database from three different servers (oracle, O2 and oracle) for a financial reporting. After data accumulated , we found more duplicate rows; business requirement was to remove all duplicate rows because of final data will be import to another system. For this purpose, I want to write script to find out duplicate rows from my table. Finally, I want to delete only duplicate rows not original row. Original row means if i have total 2 rows those same or duplicate, so I want to delete only one row that is duplicate. Let’s go............................ Step 1: Create a student Table below Script: CREATE TABLE [Students] (     [ID] [int] NULL,     [Name] [varchar] ( 50 ) NULL,     [address] [varchar] ( 50 ) NULL,     [contact] [varchar] ( 50 ) NULL,     [email] [varchar] ( 50 ) NULL ) Step 2: insert Record that shown below:   Insert Duplicate Records     Step 3: Sel

Difference between Thread and Process

A Process is an instance of a running application. And a thread is the Execution stream of the Process. A process can have multiple Thread. When a process starts a specific memory area is allocated to it. When there are multiple threads in a process, each thread gets a memory for storing the variables in it, and plus they can access the global variables which are common for all the threads. Thread: is used to execute more than one program at a time. The process can execute a single program. Thread is a path of execution that runs on the CPU, a process is collection of threads that share the same virtual memory. A process has at least one thread of execution, and a thread always runs in a process context.

Difference Between readonly and const c#

Several times I read the difference between Readonly and const keyword in C#. But most of the time when I remember the difference, again and again, mismatch the concept ..Finlay, write simple code.      public class Diff_ConstNReadonly         {             public const int cons_Value = 2;             public readonly int readOnly_value;             public Diff_ConstNReadonly ()             {                 readOnly_value = 3;             }         } Differences: Const :       1.    Const can only be initialized at the time of declaration of the field.       2.     Const values will evaluate at compile time only.       3.     Const val ue can’t be changed these will be same at all the time.       4.     This type of fields are required when one of the field values remains constant throughout the system like Pi will remain same in your Maths class. Read-only :      1.     The value will be initialized either declaration time or the constructor of the class all

TRY... CATCH IN Sql Server

Overview: A great option is included in sqlserver 2005 first that was the ability to use TRY .. CATCH block in sql server as C#. It is not easiest thing in early sqlserver. So this options are easy to handles Sql errors. Explanation If you are not familiar with the Try...Catch paradigm it is basically two blocks of code with your stored procedures that lets you execute some code, this is the Try section and if there are errors they are handled in the Catch section.  Let's take a look at an example of how this can be done.  As you can see we are using a basic SELECT statement that is contained within the TRY section, but for some reason if this fails it will run the code in the CATCH section and return the error information. -- ============================================= -- Author: <Md Maksudur Rahman> -- Create date: <20160501> -- Description: <Get students> -- EXEC uspTryCatchTest 'Mohammad' -- ====================

Database View

View is a database object also called a logical table. it has no psychical existence. It is not like a simple table, but is a virtual or logical table which contains columns and data from different tables (may be one or more tables). A View does not contain any data, it is a set of queries that are applied to one or more tables that is stored within the database as an object. After creating a view from some table(s), it used as a reference of those tables and when executed, it shows only those data which are already mentioned in the query during the creation of the View. Creating view Syntax: ------------------------------------------------- CREATE VIEW [View_Name] AS [ SELECT Statement] ------------------------------------ ------------- CREATE VIEW SampleView As SELECT EmpID, EmpName FROM EmpInfo -------------------------------------------------- Data retrieve from view: SELECT * FROM SampleView WHERE EmpID ='FN0009C1'     View does not modif

What is an Index? Explain Custered Index and Non-Clustered Index

Index Index is a database object, which can be created on one or more columns (16 Max column combination). When creating the index will read the column(s) and forms a relevant data structure to minimize the number of data comparisons. The index will improve the performance of data retrieval and adds some overhead on data modification such as create, delete and modify. So it depends on how much data retrieval can be performed on table versus how much of DML ( Insert , Delete and Update ) operations. clustered index A clustered index is something that reorganizes the way records in the table are physically stored. Therefore a table can have only one clustered index. The leaf nodes of a clustered index contain the data pages, by which I mean the key-value pair in the clustered index has the index key and the actual data value. Also remember, a clustered index will be created on a table by default the moment a primary key is created on the table. A clustered index is so

What is Stack and Heap

We are discussing about memory management, how the memory of the computer is organized for a running program. Ok lets go to discuss :-  When a program is loaded into memory, it is organized into three areas of memory, called segments: the text segment ,  stack segment , and  heap segment . The text segment:  sometimes also called the code segment  is where the compiled code of the program itself resides. The remaining two areas of system memory is where storage may be allocated by the compiler for data storage. Two areas are called Stack and Heap Stack: Stack is a data structure in memory used for storing items in last in first out manner. The  stack contains local variables and the call stack. In C#, Value types variable are stored directly on the stack.  The advantage of using the stack to store variables, is that memory is managed . we don't have to allocate memory by hand, or free it once we don't need it any more. What's more, because the CPU organizes s

What is Object Pooling (.net)

Object pooling is nothing new, it is a container that contains active object lists that are created. In a word , a container of objects that are ready for use. List of ready-to-be-used objects are keep in this pool.Whenever there is a request for a new object, the pool manager will take the request and it will be served by allocating an object from the pool.