c# - How to create an array with different data types

Array with different data types
array-with-different-data-types.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.IO" %>
    
<!DOCTYPE html>    
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)    
    {  
        object[] diffdatatypesarray = new object[8];
        diffdatatypesarray[0] = "this is a sample text.";
        diffdatatypesarray[1] = null;
        diffdatatypesarray[2] = true;
        diffdatatypesarray[3] = 2.99;
        diffdatatypesarray[4] = DateTime.Now;
        diffdatatypesarray[5] = Convert.ToDecimal(99.99);
        diffdatatypesarray[6] = Convert.ToDouble(28.20);
        diffdatatypesarray[7] = 125;

        Label1.Text = "object array with different data types.........<br />";
        foreach (object o in diffdatatypesarray)
        {
            if(o != null)
            {
            Label1.Text += o.ToString() + " || ";
            Label1.Text += o.GetType() + "<br />";
            }
        }
    }    
</script>    
    
<html xmlns="http://www.w3.org/1999/xhtml">    
<head id="Head1" runat="server">    
    <title>c# example - array with different data types</title>    
</head>    
<body>    
    <form id="form1" runat="server">    
    <div>    
        <h2 style="color:DarkBlue; font-style:italic;">    
            c# example - array with different data types
        </h2>    
        <hr width="550" align="left" color="LightBlue" />      
        <asp:Label     
            ID="Label1"     
            runat="server"    
            Font-Size="X-Large"    
            >    
        </asp:Label>    
        <br />
        <asp:Button     
            ID="Button1"     
            runat="server"     
            Text="get array with different data types"    
            OnClick="Button1_Click"  
            Height="40"    
            Font-Bold="true"    
            />    
    </div>    
    </form>    
</body>    
</html>
More c# examples