Sunday, 11 September 2016

Mathematical Calculation in C# using Math Class.

Math class can be use for maths related calculation.

some of useful math class methods are illustrated with example.

- Math.BigMul() : use for getting multiplication of two number.
- Math.Ceiling() : use for getting number that is greater than or equal to the specified double-precision floating-point number.
- Math.Floor() : use for getting integer that is less than or equal to the specified double-precision floating-point number.
- Math.Sin() : Returns the sine of the specified angle.
- Math.Cos() : Returns the cosine of the specified angle.
- Math.Tan() : Returns the tangent of the specified angle.
- Math.Sqrt() : Returns the square root of a specified number.
- Math.Max() : Returns the larger of two number.
- Math.Min() : Returns the smaller of two number.

using System;

namespace CsharpProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            double Multiplication, CeilingValue, FloorValue;

            Multiplication = Math.BigMul(7823, 2345);

            CeilingValue = Math.Ceiling(76.43);

            FloorValue = Math.Floor(76.43);

            Console.WriteLine("7823 * 2345 = " + Multiplication);

            Console.WriteLine("Ceiling value of 76.43 is " + CeilingValue);

            Console.WriteLine("Floor value of 76.43 is " + FloorValue);

            double sin_Result, cos_Result, tan_Result;

            sin_Result = Math.Sin(30);
            cos_Result = Math.Cos(30);
            tan_Result = Math.Tan(30);

            Console.WriteLine("Sin of angle 30 is " + sin_Result);
            Console.WriteLine("Cos of angle 30 is " + cos_Result);
            Console.WriteLine("Tan of angle 30 is " + tan_Result);

            double SquareRoot;

            SquareRoot = Math.Sqrt(144);

            Console.WriteLine("Square Root of 144 is " + SquareRoot);

            int MaxValue, MinValue;

            MaxValue = Math.Max(34, 76);
            MinValue = Math.Min(34, 76);

            Console.WriteLine("Maximum of 34 and 76 is " + MaxValue);
            Console.WriteLine("Minimum of 34 and 76 is " + MinValue);

            Console.ReadKey();
        }
    }
}

Hello World in C#.Net

Hello World Program in C#.Net

using System;

namespace CsharpProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}


Here Console.WriteLine() is use to display message to console screen.
Console.ReadKey(); is used to retain console screen , it will wait for user to press any key.


c# program which ask for your name and write it back with Greet.

using System;

namespace CsharpProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            string Name;
            Console.WriteLine("Please enter your name!");
            Name = Console.ReadLine();

            Console.WriteLine("Hello, Your name is " + Name);
            Console.ReadKey();
        }
    }
}

Console.ReadLine() is use to read message entered by user.

Friday, 9 September 2016

you can call javascript function from code behind using ScriptManager.

Declare required function in javascript,

<script type="text/javascript" language="javascript">
    function GetMessage() {
        alert("hello!")
    }
</script>

Write below line where you want to call Javascript function,
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "smMain", "GetMessage();", true);

Tuesday, 2 August 2016

Verbatim String

This are type of string which do not require to be escaped, like a filename:

string myFileName = "C:\\DotNet\\ReadMe.txt"; Can be replace with
string myFileName = @"C:\DotNet\ReadMe.txt";

The @ symbol means to read that string literally.

verbatim string can also have multi line.

String MultilineString = @" This is
                                           a multi line
                                          string which is span
                                          in 4 lines";

Friday, 29 July 2016

Hide Label Tag after some seconds(3 Second) in ASP.NET

Add below java script in .aspx page

 <script type="text/javascript">
        function HideLabelText() {
            var _Second = 3; // Specify duration in second
            setTimeout(function () {
                document.getElementById("<%=lblMessage.ClientID %>").style.display = "none";
            }, _Second * 1000); 
        };
  </script>
 
  lblMessage is a ID of Label control
  _Second = 3 i.e It will hide label after 3 seconds , you can change this as per your need.

Add below lines in the event handler in your code.

C#.NET : ClientScript.RegisterStartupScript(this.GetType(), "alert", "HideLabelText();", true); 
VB.NET : ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "HideLabelText();", True)