Order class example

Order class: public class Order { public int OrderID; public string CustomerID; public int EmployeeID; public DateTime OrderDate; public DateTime RequiredDate; public DateTime ShippedDate; public int ShipVia; public decimal Freight; public string ShipName; public string ShipCity; public string ShipRegion; public string ShipCountry; public List <Order_Detail> Order_Details; public Customer Customer; public Employee Employee; public Shipper Shipper; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Generate a list of objects and bind to a GridView in C#

The class: using System; public class Movie { public string Title { get; set; } public string Director { get; set; } public int Genre { get; set; } public int RunTime { get; set; } public DateTime ReleaseDate { get; set; } } protected void Page_Load(object sender, EventArgs e) { var movies = GetMovies(); […]
Continue reading…

Enjoyed this post? Share it!

 
 

Handling Events in c# .NET

To handle an event you need to subscribe to it by providing an event handler method whose return type and parameters match that of the delegate specified for use with the event. The following example uses a simple timer object to raise events, which results in a handler method being called. using System; using System.Collections.Generic; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Serializing and Deserializing Objects in c# .NET

The .NET Framework provides the infrastructure to serialize objects in the System.Runtime.Serialization and System.Runtime.Serialization.Formatters namespaces. System.Runtime.Serialization.Formatters.Binary—This namespace contains the class BinaryFormatter, which is capable of serializing objects into binary data, and vice versa. System.Runtime.Serialization.Formatters.Soap— This namespace contains the class SoapFormatter, which is capable of serializing objects into SOAP format XML data, and vice versa. Serializing […]
Continue reading…

Enjoyed this post? Share it!

 
 

Dynamically sized array of objects of a specific type in c# .NET

To declare a dynamically sized array of objects of a specific type we can use a generic list List to create a list of objects of type T, in csharp .NET. class Person { public string Name { get; set; } public string Address { get; set; } }   static void Main(string[] args) { […]
Continue reading…

Enjoyed this post? Share it!

 
 

How to provide a string representation of an object for output and debugging purposes.

By default, ToString() will display the type’s name. To show your own values, you must override the ToString() method. struct My3d { private double _x; private double _y; private double _z; public double X { get { return _x; } set { _x = value; } }   public double Y { get { return […]
Continue reading…

Enjoyed this post? Share it!

 
 

Difference in declaring interfaces in C# and VB

C# uses the interface statement along with opening and closing braces to indicate the beginning and end of an interface definition. For example: public interface IDataAdapter { // Member definitions } In VB, an interface definition is indicated by the Interface… End Interface construct: Public Interface IDataAdapter ‘ member definitions End Interface C# uses the […]
Continue reading…

Enjoyed this post? Share it!

 
 

Difference in declaring structures in C# and VB

C# uses the struct statement along with opening and closing braces to indicate the beginning and end of a structure definition. Example defined in C#: public struct SomeStruct { // Member definitions } In VB, a structure definition is indicated by the Structure… End Structure construct: Public Structure SomeStruct ‘ member definitions End Structure
Continue reading…

Enjoyed this post? Share it!

 
 

Difference in inheritence declaration in C# and VB

C# uses the colon to indicate either inheritance or interface implementation. Both the base class and the implemented interfaces are part of the class statement. Example: public class DataSet : MarshalByValueComponent, IListSource, ISupportInitialize, ISerializable In VB, the base class and any implemented interfaces are specified on separate lines immediately following the Class statement. A class’s […]
Continue reading…

Enjoyed this post? Share it!

 
 

Difference in declaring classes in C# and VB

C# uses the class statement along with opening and closing braces, { }, to indicate the beginning and end of a class definition. For example: public class DataException : SystemException { // Member definitions } In VB, a class definition is indicated by the Class… End Class construct: Public Class DataException Inherits SystemException ‘ member […]
Continue reading…

Enjoyed this post? Share it!

 
 

Private Constuctors in C# (Csharp)

Private constructor are very important feature used extensively in Object oriented design and development. They are used when you don’t want to instantiate class and at the same time use its members. They are used when class only has static members. Class Calculator { public static double e = 2.71828; private Calculator() { } public […]
Continue reading…

Enjoyed this post? Share it!

 
 

Differences between class and structure c#

Following are the differences between structure and classes 1. Structures are value type and Classes are reference type. 2. Structures can not have constructor or destructor. Classes can have both constructor and destructor. 3. Structures do not support Inheritance, while Classes support Inheritance
Continue reading…

Enjoyed this post? Share it!

 
 

Constructor Initializers Are Called Bottom-Up But Constructors Are Invoked Top-Down Starting With Constructor In Base Class – Class Interface

using System; public class Starter { public static void Main() { XClass obj = new XClass(); } }public class MyClass { public MyClass(int param) { Console.WriteLine("MyClass constructor"); } }public class YClass : MyClass { public YClass(int param) : base(YClass.MethodA()) { Console.WriteLine("YClass constructor"); } public static int MethodA() { Console.WriteLine("YClass constructor initializer"); return 0; } }public […]
Continue reading…

Enjoyed this post? Share it!

 
 

Demonstrate Readonly – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// Demonstrate readonly.   using System;   class MyClass { public static readonly int SIZE = 10; }   public class DemoReadOnly { public static void Main() { int[]nums = new int[MyClass.SIZE];   for(int i=0; i<myClass.SIZE; i++) nums[i] = i; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Four Layers Of Class Hierarchy – Class Interface

/* * C# Programmers Pocket Consultant * Author: Gregory S. MacBeth * Email: gmacbeth@comporium.net * Create Date: June 27, 2003 * Last Modified Date: */ using System;namespace Client.Chapter_5___Building_Your_Own_Classes { public class MyMainClass3 { static void Main(string[] args) { //The function called is based //upon the type called by new. A MyA = new D(); B […]
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrates Use Of Struct – Class Interface

/* Mastering Visual C# .NET by Jason Price, Mike GunderloyPublisher: Sybex; ISBN: 0782129110 *//* Example5_15.cs illustrates the use of a struct */// declare the Rectangle struct struct Rectangle { // declare the fields public int Width; public int Height; // define a constructor public Rectangle(int Width, int Height) { this.Width = Width; this.Height = Height; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Method Overloading Test – Class Interface

/* Learning C# by Jesse LibertyPublisher: O’Reilly ISBN: 0596003765 */ using System; namespace MethodOverloading { public class Time1 { // private member variables private int Year; private int Month; private int Date; private int Hour; private int Minute; private int Second; // public accessor methods public void DisplayCurrentTime() { System.Console.WriteLine("{0}/{1}/{2} {3}:{4}:{5}", Month, Date, Year, Hour, […]
Continue reading…

Enjoyed this post? Share it!