MVC using console program

This short article shows you how to create a MVC program using C# Console project.

MVC is a pattern that does not bound to any programming language. It belongs to neither Java nor .NET.

I modified the sample from to put all the classes in a single file.

Main Program

class Program


    static void Main(string[] args)



            TipCalculatorController t = new TipCalculatorController();





The Model

class Tip


    //private fields

    private double amount;

    private double tipPercent;

    //default constructor

    public Tip()


        Amount = 0;

        TipPercent = 0;


    //overloaded constructor

    public Tip(double amt, double percent)


        Amount = amt;

        TipPercent = percent;


    //public properties

    public double Amount


        get { return amount; }

        set { amount = value; }


    public double TipPercent


        get { return tipPercent; }



            if (value > 1)


                value /= 100;


            tipPercent = value;



    public double CalculateTip()


        //very simplistic tip calculation

        return Amount * TipPercent;


    public double CalculateTotal()


        //simple total calculation

        return CalculateTip() + Amount;




The View


class Display



    //private fields

    private double perc;

    private double amt;

    private double total;

    private double tipAmount;



    public Display()


        Percentage = 0;

        TipAmount = 0;

        Amt = 0;

        Total = 0;




    //public properties

    public double TipAmount


        get { return tipAmount; }

        set { tipAmount = value; }




    public double Total


        get { return total; }

        set { total = value; }




    public double Percentage


        get { return perc; }

        set { perc = value; }



    public double Amt


        get { return amt; }

        set { amt = value; }



    private void GetValues()


        Console.WriteLine(“Enter the Amount of the meal”);

        Amt = double.Parse(Console.ReadLine());


        Console.WriteLine(“Enter the percent you want to tip”);

        Percentage = double.Parse(Console.ReadLine());



    public void ShowTipandTotal()


        Console.WriteLine(“Your tip is {0:C}”, TipAmount);

        Console.WriteLine(“The total will be {0:C}”, Total);





The Controller


class TipCalculatorController


    private Tip tip;

    private Display display;


    public TipCalculatorController()


        display = new Display();

        tip = new Tip(display.Amt, display.Percentage);

        display.TipAmount = tip.CalculateTip();

        display.Total = tip.CalculateTotal();




You can also download the source code from The sample file name My MSN ID is

Posted in .Net, Community | Tagged , , , | Leave a comment

Windows 10 Developer Readiness

We’re excited to offer a series of live webcasts that deliver first-hand guidance on how you can leverage the new Windows 10 development model. The webcasts will be presented and moderated by Microsoft MVPs around the world at no charge and are a great opportunity for you to not only learn the foundations of Universal App Development in Windows 10, but also to connect with some of the top experts in your country and/or language. Bring your Windows Store app development questions and have them answered live, by the experts, and learn how to take advantage of the great opportunities ahead in the Universal Windows Platform.
  • Each webcast will deliver the same content in different countries from June 8 – 12.
  • They will last from one to three hours, depending on the amount of community interaction.

Microsoft is empowering the MVPs with technical content and private training so every session will be fully equipped with content, demos, and up-to-date guidance.

We hope you join and connect with us for this great worldwide initiative!
Posted in .Net, Community | Tagged , | Leave a comment

Microsoft SQL Server 2016 Preview Sign Up

You can sign up for Microsoft SQL Server 2016 Preview at the below link:

I am still waiting for the email notification after signed up.

Posted in .Net, Community | Tagged , , | Leave a comment

WCF Interview Questions

I found few good webpages on WCF interview question.

1. Interview Questions Answers – Windows Communication Foundation (WCF)

2. WCF – Top 10 Interview Questions

3. WCF Interview Questions and Answers

4. Top WCF interview questions and answers job interview tips

Posted in .Net, Community | Tagged , , , | Leave a comment

WPF Interview Questions

I found few good webpages on WPF interview question.

1. WPF Interview questions with answers – CodeProject

2. WPF Interview Questions

3. Top wpf interview questions and answers job interview tips

4. WPF Interview Questions and Answers

Posted in .Net, Community | Tagged , , | Leave a comment

Binding Dataset to GridView using SqlDataSource

This short article shows you how to bind GridView to Dataset using SqlDataSource.

Refer back to the article . That article is using C# code to bind Dataset to GridView. You can also bind Dataset to GridView with using C# code but SqlDataSource.

You still need a web.config like below.

<?xml version=1.0 encoding=utf-8?>


  For more information on how to configure your ASP.NET application, please visit




    <compilation debug=true targetFramework=4.5 />

    <httpRuntime targetFramework=4.5 />




      <add name=NorthWindConnectionString connectionString=data source=.\SQLEXPRESS;initial catalog=northwind;integrated security=True providerName=System.Data.SqlClient />




The aspx page with SqlDataSource as below.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”WebForm1.aspx.cs” Inherits=”WebAppGridView.WebForm1″ %>


<!DOCTYPE html>


<html xmlns=””&gt;

<head runat=”server”>




    <form id=”form1″ runat=”server”>


      <h3>GridView DataBind Example</h3>

      <asp:label id=”Message”




      <asp:gridview id=”AuthorsGridView”


        runat=”server” DataKeyNames=”CustomerID” DataSourceID=”SqlDataSource1″>


              <asp:BoundField DataField=”CustomerID” HeaderText=”CustomerID” ReadOnly=”True” SortExpression=”CustomerID” />

              <asp:BoundField DataField=”CompanyName” HeaderText=”CompanyName” SortExpression=”CompanyName” />

              <asp:BoundField DataField=”ContactName” HeaderText=”ContactName” SortExpression=”ContactName” />

              <asp:BoundField DataField=”ContactTitle” HeaderText=”ContactTitle” SortExpression=”ContactTitle” />

              <asp:BoundField DataField=”Address” HeaderText=”Address” SortExpression=”Address” />

              <asp:BoundField DataField=”City” HeaderText=”City” SortExpression=”City” />

              <asp:BoundField DataField=”Region” HeaderText=”Region” SortExpression=”Region” />

              <asp:BoundField DataField=”PostalCode” HeaderText=”PostalCode” SortExpression=”PostalCode” />

              <asp:BoundField DataField=”Country” HeaderText=”Country” SortExpression=”Country” />

              <asp:BoundField DataField=”Phone” HeaderText=”Phone” SortExpression=”Phone” />

              <asp:BoundField DataField=”Fax” HeaderText=”Fax” SortExpression=”Fax” />



        <asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:NorthWindConnectionString %> SelectCommand=”SELECT * FROM [Customers]”></asp:SqlDataSource>





There is no code behind for this method.

You can also download the source code from The sample file name My MSN ID is

Posted in .Net, Community | Tagged , , , | Leave a comment

Run Visual Studio in Mac OS and Linux

This short article shows you how to run C# code in Mac OS and Linux.

Microsoft announces a tool call Visual Studio Code. You can download the tool here

Watch the video, the video is showing running this tool in Mac with Mac OS (not someone using Mac to run Windows).

But … for me I hit error when I try to run it.



I am still looking at how to run a simple html page in it.

Posted in .Net, Community, Operating System | Tagged , , , , | Leave a comment