Author Topic: Simple Console Application in C# .NET  (Read 2350 times)

hcengiz

  • Administrator
  • Newbie
  • *****
  • Posts: 9
    • View Profile
Simple Console Application in C# .NET
« on: August 22, 2007, 07:00:49 AM »
The organization of the codes in C# consists of two main code blocks:

   1. namespace
   2. class

namespaces can include different classes. We can place the codes of each of the classes in different files.
-In this example, the class including the main program is named class Program{} and saved in Program.cs file.
-On the other hand, the second class including the functions for the interest calculation is named class InterestFunctions{} and is saved in InterestFunctions.cs file.

Both classes are implemented under the SAME namespace called namespace Interest{}.

Program.cs

Code: [Select]
using System;
    using System.Collections.Generic;
    using System.Text;


    namespace Interest
    {
    class Program
    {
    static void Main(string[] args)
    {
    Console.WriteLine("Enter the money (p):");
    int p = int.Parse(Console.ReadLine());
    Console.WriteLine("Enter the rate of interest (R):");
    double R = double.Parse(Console.ReadLine());
    Console.WriteLine("Enter the time (T):");
    int T = int.Parse(Console.ReadLine());

    InterestCalc IC = new InterestCalc();
    Console.WriteLine("Simple Interest:");
    Console.WriteLine(IC.CalculateSimpleInterest(p, R, T));
    Console.WriteLine("Compound Interest:");
    Console.WriteLine(IC.CalculateCompoundInterest(p, R, T));
    Console.Read();
    }
    }
    }
   

InterestFunctions.cs

Code: [Select]
using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Interest
    {
    class InterestCalc
    {
    public InterestCalc()
    {
    }

    public double CalculateSimpleInterest(int p, double r, int t)
    {
    return (p*r*t)/100;
    }

    public double CalculateCompoundInterest(int p, double r, int t)
    {
    return p*(1+r/100)*t;
    }
    }
    }

source: http://csharpeasy.blogspot.com
« Last Edit: October 11, 2007, 07:05:07 AM by hcengiz »

Engineer Forum

Simple Console Application in C# .NET
« on: August 22, 2007, 07:00:49 AM »