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!

 
 

Parameterized Constructor – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // A parameterized constructor.   using System;   class MyClass { public int x;   public MyClass(int i) { x = i; } }   public class ParmConsDemo { public static void Main() { MyClass t1 = new MyClass(10); […]
Continue reading…

Enjoyed this post? Share it!

 
 

Demonstrate Structure – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Demonstrate a structure.   using System;   // Define a structure. struct Book { public string author; public string title; public int copyright;   public Book(string a, string t, int c) { author = a; title = t; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Explicitly Implement Interface Member – Class Interface

/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */// Explicitly implement an interface member.   using System;   interface IEven { bool isOdd(int x); bool isEven(int x); }   class MyClass : IEven { // explicit implementation bool IEven.isOdd(int x) { if((x%2) != 0) return true; else return […]
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrates Overloaded Constructors – Class Interface

/* Mastering Visual C# .NET by Jason Price, Mike GunderloyPublisher: Sybex; ISBN: 0782129110 *//* Example5_12.cs illustrates overloaded constructors */// declare the Car class class Car { // declare the fields private string make; private string model; private string color; private int yearBuilt; // define the overloaded constructors public Car() { this.make = "Ford"; this.model = […]
Continue reading…

Enjoyed this post? Share it!

 
 

Issue Error Message If You Do Not Initialize All Of Fields In Structure – Class Interface

/* C# Programming Tips & Techniques by Charles Wright, Kris JamsaPublisher: Osborne/McGraw-Hill (December 28, 2001) ISBN: 0072193794 */// // Struct.cs – Issue an error message if you do not initialize all of // the fields in a structure // // Compile this program with the following command line: // C:>csc Struct.cs // using System;namespace nsStruct […]
Continue reading…

Enjoyed this post? Share it!