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!

 
 

Abstract Classes And Methods – Class Interface

using System;abstract public class MotorVehicle { public string make; public string model; public MotorVehicle(string make, string model) { this.make = make; this.model = model; } abstract public void Accelerate();}public class Product : MotorVehicle { public Product(string make, string model) : base(make, model) { // do nothing } public override void Accelerate() { Console.WriteLine("In Product Accelerate() […]
Continue reading…

Enjoyed this post? Share it!

 
 

Calling Function With Structure Parameter – Class Interface

/* A Programmer’s Introduction to C# (Second Edition) by Eric GunnersonPublisher: Apress L.P. ISBN: 1-893115-62-3 */// 31 – Interop\Calling Native DLL Functions\Calling a Function with a Structure Parameter // copyright 2000 Eric Gunnerson using System; using System.Runtime.InteropServices;struct Point { public int x; public int y;   public override string ToString() { return(String.Format("({0}, {1})", x, y)); […]
Continue reading…

Enjoyed this post? Share it!

 
 

Declare Class Address Containing Data Members To Describe Us Address Along With Member Functions – Class Interface

using System;class MainClass { public static void Main(string[] args) { Address addr = new Address(); addr.SetStreet(123, "My Street"); addr.SetCity("A", "X", 123456); Console.WriteLine(addr.GetStreetString()); Console.WriteLine(addr.GetCityString()); addr.Output(); } }class Address { public int nAddressNumberPart; public string sAddressNamePart; public string sCity; public string sState; public int nPostalCode; public void SetStreet(int nNumber, string sName) { nAddressNumberPart = nNumber; sAddressNamePart = […]
Continue reading…

Enjoyed this post? Share it!

 
 

Demonstrates Using Structure To Return Group Of Variables From Function – Class Interface

/* C# Programming Tips & Techniques by Charles Wright, Kris JamsaPublisher: Osborne/McGraw-Hill (December 28, 2001) ISBN: 0072193794 */// tm.cs – demonstrates using a structure to return a group of variables // from a function // // Compile this program using the following command line: // D:>csc tm.cs // namespace nsStructure { using System; using System.Globalization; […]
Continue reading…

Enjoyed this post? Share it!

 
 

Illustrates How To Declare Classes, Object References, And Create Objects – Class Interface

/* Mastering Visual C# .NET by Jason Price, Mike GunderloyPublisher: Sybex; ISBN: 0782129110 *//* Example5_1.cs illustrates how to declare classes, object references, and create objects */// declare the Car class class Car { // declare the fields public string make; public string model; public string color; public int yearBuilt; // define the methods public void […]
Continue reading…

Enjoyed this post? Share it!