Posts

Showing posts with the label C#

C# Fundamental: Stack vs. Heap

Image
Memory Allocation (Stack and Heap) Operating system and language runtimes such as .NET CLR divides the memory into two chunks called stack ad heap. Stack and heap act differently while allocating memory. When we call a method, the memory required for its parameters ad variable is accommodated by the stack. When a method finishes its job, the memory is automatically released by the garbage collector for the purpose of reuse. Stack Memory Stack is organized like stack of boxes sitting on top of one another. When a method is called, each parameter is put into a box, first box goes first into stack then second on top of it, and so on. As in the following diagram: Stack uses Last In First Out (LIFO) mechanism for allocating memory. Heap Memory Heap memory is an unorganized pile of boxes sitting in a room randomly, not like stack which stored boxes on top of each other in an order. The reference to the object is stored on stack but the actual value is stored on heap....

C# Fundamental: Value and Reference Types

Image
Data Types There are following data types in C#: Value type Reference type Value Type Value types directly contain data Allocated on stack It cannot be  null Data types such as integers, numeric, bytes, Booleans,  char  are called value type. Value types are derived from the  ValueType  class in  System namespace . There are two categories of value types which are built in and user defined. Built in value types  are  int ,  char ,  decimal ,  float ,  long , etc. and User defined  value types are structures ( DateTime  is a value type, a structure) and  enum . For example, when we declare the  int a  compiler allocates 4 bytes of memory (32bit). When we give a value such as 7 to the variable, it copies this value to that block of memory. We can declare a data type by writing the data type name like  int string , etc. then write any name of a variable by using name conve...

C# Fundamental: Data Types and Variable

Image
Data Types In C#, data types are used to store values in the memory. When data type is declared, it allocates a block of memory to hold the value. All the data types are directly or indirectly derived from the  System.object  class. Before moving, we need to understand the variables. Variables A variable is used to store the value (data). It is an address given to a memory location. Example: Take an example of a bag here bag is a variable we can put books into a bag and we can take them out again but we can put books according to bag size, a bigger bag can hold more books. Similarly, we can store and retrieve data from a variable. Here bag is the variable name the size of bag is the data type, an  int  can hold 32 bit value and  long  can hold 64 bit value. Different data types have different sizes we use them according to our requirement for example if we want to store only two values  true  or  false  we...

A detailed introduction to " C# Fundamental "

Introduction Data types are the building block of any programming language. These are like the grammar of any language. I have explained in detail the data types, memory allocation on stack and heap, variables, naming conventions. Topics covered are as follows: Data types Variables Naming convention Value type/reference type Stack/heap memory Note:-- All examples are created by using VS 2015 enterprise edition. Related Topics: Data Types and Variable, Value and Reference Types,   Stack vs. Heap

C# : Check value stored inside string object is decimal or not

Use the Decimal.TryParse function. decimal value ; if ( Decimal . TryParse ( strOrderId , out value )) // It's a decimal else // No it's not. You can use Decimal.TryParse to check if the value can be converted to a Decimal type. You could also use Double.TryParse instead if you assign the result to a variable of type Double. MSDN example: string value = "1,643.57" ; decimal number ; if ( Decimal . TryParse ( value , out number )) Console . WriteLine ( number ); else Console . WriteLine ( "Unable to parse '{0}'." , value ); use  Decimal.TryParse   to check if the string entered is decimal or not.   decimal d ; if ( decimal . TryParse ( textBox1 . Text , out d )) { //valid } else { //invalid MessageBox . Show ( "Please enter a valid number" ); return ;   }  

How to bind dropdownlist inside gridview edit template

Image
Overview:   This article explains how to bind drop down list control which is placed inside Asp.net   Gridview  control under Edit Template. .i.e Gridview edit template dropdownlist bind. Also using  DataRowView  we able to get and set gridview edit template drop-down list value. On ".aspx" Page: Add gridview on design page like: On ".aspx.cs" Page: Page_load Bind gridview control: Yeah, we are done now :-) Hope you enjoyed this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!

Edit all rows of gridview on button click which is outside gridview

Image
I have a "Submit Objection" button in my page. on click of the edit button i want Owner Name. My gridview is in a web user control and button on an aspx page. The Code behind design: Here the fire event of Submit Objection button:    The Code behind Submit Objection code is: For More Help: Follow the link  edit all rows of gridview on button click which is outside gridview