DivRem Example Syntax C-Sharp ASP.NET | C# DivRem | Source Code
DivRem Example Syntax C-Sharp ASP.NET | C# DivRem | Source Code
Summary: – Illustrates using DivRem with Source Code Syntax Example in C-Sharp ASP.NET.
Purpose:
takes an dividend, divisor, and remainder as Int32 or Int64
and returns quotient as same data type. Remainder is passed by
reference and it gets updated with the remainder when the function
executes.
Syntax:
DivRem(dividend32, divisor32, byRef remainder32)
DivRem(dividend32, divisor32, byRef remainder32)
Parameters | Description | dividend32 | int32 |
---|---|
divisor32 | int32 |
remainder32 | byRef int32 |
Result Data Type | Description | int32 | quotient |
---|
Syntax2:
DivRem(dividend64, divisor64, byRef remainder64)
DivRem(dividend64, divisor64, byRef remainder64)
Parameters | Description | dividend64 | int64 |
---|---|
divisor64 | int64 |
remainder64 | byRef int64 |
Result Data Type | Description | int64 | quotient |
---|
Quick Example | Dim int32Dividend As Int32 = 7 Dim int32Divisor As Int32 = 5 Dim int32Quotient As Int32 = 0 Dim int32Remainder As Int32 = 0 int32Quotient = Math.DivRem(int32Dividend, int32Divisor, out int32Remainder); TextBox1.Text = “Quotient=” + int32Quotient; Returns 1 |
---|
Step 1: Click on cs to Cut-n-paste code into DivRem.aspx.cs
using System; using System.IO; using System.Data; //******************************************************************************** // Purpose: takes an dividend, divisor, and remainder as Int32 or Int64 // and returns quotient as same data type. Remainder is passed by // reference and it gets updated with the remainder when the function // executes. // // ******************************************************************************* // Syntax: DivRem(dividend32, divisor32, byRef remainder32) // // Parameter1: dividend32 - int32 // // Parameter2: divisor32 - int32 // // Parameter3: remainder32 - byRef int32 // // Result: int32 - quotient // // ****************************************************************************** // Syntax2: DivRem(dividend64, divisor64, byRef remainder64) // // // Parameter1: dividend64 - int64 // // Parameter2: divisor64 - int64 // // Parameter3: remainder64 - byRef int64 // // Result: int64 - quotient // // Quick Example: Dim int32Dividend As Int32 = 7 // Dim int32Divisor As Int32 = 5 // Dim int32Quotient As Int32 = 0 // Dim int32Remainder As Int32 = 0 // int32Quotient = Math.DivRem(int32Dividend, int32Divisor, out int32Remainder); // TextBox1.Text = "Quotient=" + int32Quotient; // Returns 1 partial class _DivRem : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { Label1.Text = "Example #1: DivRem(dividend as int32, divisor as int32, byRef remainder as int32)"; Int32 int32Dividend = 7; Int32 int32Divisor = 5; Int32 int32Quotient = 0; Int32 int32Remainder = 0; int32Quotient = Math.DivRem(int32Dividend, int32Divisor, out int32Remainder); TextBox1.Text = "Quotient=" + int32Quotient; // Returns 1 Label2.Text = "Example #2: DivRem(dividend as int64, divisor as int64, byRef remainder as int64)"; Int64 int64Dividend = 7; Int64 int64Divisor = 5; Int64 int64Quotient = 0; Int64 int64Remainder = 0; int64Quotient = Math.DivRem(int64Dividend, int64Divisor, out int64Remainder); TextBox2.Text = "Quotient=" + int64Quotient; // Returns 1 } } |
Step 2: Click on XML to Cut-n-paste code into DivRem.aspx
< %@ Page Language="VB" AutoEventWireup="false" CodeFile="DivRem.aspx.cs" Inherits="_DivRem" %> < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h1><asp:label ID="Label1" runat="server" Text="Label"></asp:label> </h1> <asp:textbox ID="TextBox1" runat="server"></asp:textbox><br /> <h1><asp:label ID="Label2" runat="server" Text="Label"></asp:label> </h1> <asp:textbox ID="TextBox2" runat="server"></asp:textbox><br /> <h1><asp:label ID="Label3" runat="server" Text="Label"></asp:label> </h1> <asp:textbox ID="TextBox3" runat="server"></asp:textbox><br /> </div> </form> </body> </html> |
Prerequistes:
- Install Visual Web Developer 2010
- Install SQL Server Express
- Download Northwind and Pubs Databases
- Attach Northwind Database to Databases in Sql Express
- Attach pubs Database to Databases in Sql Express
Notes:
- You can build your own library of syntax examples by using same web site over and over and just add new web forms to it.
Instructions:
- Use Visual Web Developer 2010
- Create new web site;
- Click File/New Web Site
- Select ASP.NET Website Template
- Select C-Sharp for Language
- name of Web Site could be CSharp_ASPNET_Syntax.
- Add New folder named “Functions”
- Right-click project name in solution explorer;
- add new folder;
- name of folder could be: Functions
- Add New subfolder named “MathFunctions”
- Right-click Functions folder in solution explorer;
- add new folder;
- name of folder could be: MathFunctions
- Add Web Form Named DivRem to MathFunctions folder
- Right-click MathFunctions folder;
- add new item;
- Select Web Form
- Check place code behind in separate file
- Web Form name could be DivRem
- Click on cs in step 1 at the top of this page to copy code into code-behind DivRem.aspx.cs
- Click on XML in step 2 above to copy code into web form DivRem.aspx
- Right-click on DivRem.aspx in solution explorer and select view in browser