Skip to main content

Posts

Showing posts with the label array in asp.net c#

How to create a DataTable from a class?

Using Reflection to create a DataTable from a Class? //How to create a DataTable from a Class? public static DataTable CreateDataTable < T > (IEnumerable < T > list) { Type type = typeof(T); var properties = type . GetProperties (); DataTable dataTable = new DataTable(); foreach (PropertyInfo propertyinfo in properties) { dataTable . Columns .Add(new DataColumn( propertyinfo . Name , Nullable . GetUnderlyingType ( propertyinfo . PropertyType ) ?? propertyinfo . PropertyType )); } foreach (T entity in list) { object[] values = new object[ properties . Length ]; for ( int i = 0 ; i < properties . Length ; i + + ) { values [i] = properties[i].GetValue(entity); } dataTable . Rows .Add( values ); } return dataTable; }

ASP.NET C# 6.0 Features that every ASP.NET Developer should know about it!

  ASP.NET C# 6.0 Features that every ASP.NET Developer should know about it.         1. Auto-property  initializes         public int ID { get ; set ; }         public bool Role { get ; set ; } = true ;         public string Name { get ; set ; } = string .Empty;         public DateTime CreatedDate { get ; set ; } = DateTime .Now;        2. Expression bodied members                     public string Name => string .Format( "{0} {1}" , FirstName, LastName);         3. Getter-only auto-properties                     public DateTime Bi...

Array Collection in ASP.Net C#

Array  is a collection of similar data type . It contains the fixed length with same data type. int [] arr= new int [10]; // One dimension Here the int array contains the 10 item, item starting from 0 to 9. Array indexing  is start with zero (0th- position) and the last position is total minus one (Total no of array -1).  But dynamic array not have predefined size. It dynamically manages the size when you add the item in the list. Types of Arrays One-dimensional Arrays  Two-dimensional Arrays  Jagged Arrays  Mixed Arrays  1. One-dimensional Arrays double [] doubleArray = new double [15]; char [] charArr = new char [15]; bool [] boolArr = new bool [20]; string [] stringArr = new string [100]; Array Properties IsFixedSize => Return a value indicating if an array has a fixed size or not.  IsReadOnly => Return a value indicating if an array is read-only or not.  LongLength ...