Tuesday, March 27, 2018

C# Tutorial : Introduction of C#

1 : Introducing C#

 

What is C#?

------------------------------------------
C#('C Sharp') is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft.

It has been designed to support the key feature of .Net Framwork.
It is a simple efficent, productive and type-safe language.
It is a purely objected-oriented, modern language suitable for developing Web based application.

Features of C#

------------------------------------------
It has numerous strong programming features that make it endearing to a number of programmers worldwide.

The important features of C# as follows −

  • Automatic Garbage Collection
  • Versioning support
  • Strict type-safety
  • Delegates and Events
  • Boxing and Unboxing
  • Web Services
  • Properties to access data members.
  • Boolean Conditions
  • Standard Library
  • Assembly Versioning
  • Properties and Events
  • Easy-to-use Generics
  • Indexers
  • Conditional Compilation
  • Simple Multithreading
  • LINQ and Lambda Expressions
  • Integration with Windows

Characteristics of C#

------------------------------------------
C# is designed for both computing and communications. The key feature are as followes :
  • Simple
  • Consistent
  • Modern
  • Object-oriented
  • Type-safe
  • Versionable
  • Compatible
  • Interoperable and  
  • Flexible

Thursday, March 22, 2018

Swap Value of Two Variable Without Using 3rd Variable


The below code swaps two given values of variables without using the third variable in C#.


<!DOCTYPE html>
 <head></head>
 <body>
  <form>
   <div>
   <h3>Swap Value of Two Variable Without Using 3rd Variable</h3>
   <p><u>Value before swaping </u></p>
   Value of A :<asp:Label ID="lblA" runat="server"></asp:Label><br />
   Value of B :<asp:Label ID="lblB" runat="server"></asp:Label><br />
   <p><u>Value after swaping </u></p>
   Value of A :<asp:Label ID="lblAS" runat="server"></asp:Label><br />
   Value of B :<asp:Label ID="lblBS" runat="server"></asp:Label><br />
   </div>
  </form>
 </body>
 </html>

C# Code for swapping value of variable :

protected void Page_Load(object sender, EventArgs e)
 {
  int a = 10, b=20;
  lblA.Text = a.ToString();
  lblB.Text = b.ToString();
  a = a + b;
  b = a - b;
  a = a - b;
  lblAS.Text = a.ToString();
  lblBS.Text = b.ToString();
}

Friday, March 16, 2018

How to use if... else condition to show/hide text in HTML?

How to use if... else condition to show/hide text in HTML?

Here i want to Show/Hide the text in HTML page as per condition OR as per rights.

This depends on the exact details / condition that we want to use to determine if something should be displayed or not. 

For example, you could use the User.Identity.IsAuthenticated property to determine if a login user has rights to see this:

<!-- Conditionally display Show or Hide -->
<% if(User.Identity.IsAuthenticated){ %>
     <b>Show</b>
<% } else { %>
     <b>Hide</b>
<% } %>

And you also apply this in the <ul><li></li></ul> only if condition:

<ul>
              <li><a href="#">Home</a></li>
       <% if (User.Identity.IsAuthenticated){ %>
              <li><a href="#">Dashboard</a></li>

       <% } %>
</ul>

Thursday, March 8, 2018

Populate DropDownList using a List



Here i am going to populate statically DataTextField and DataValueField in DropDownList using c#.


ddlName.Items.Insert(0, new ListItem("-- Select --", "0"));

Note : In above, there is
       first zero stands for position of ListItem and
       second zero is DataValue of the ListItem and
       "-- Select --"  is the DataText for visible in DropDown.

Add Asp:DropDownList Control to the page like:

  <tr>
    <td><b>Name</b></td>
    <td><asp:DropDownList ID="ddlName" runat="server"</asp:DropDownList></td>
  </tr>

Add C# code to bind the Name to the DropdownList as below :

  private void BindNames()
   {
    ddlName.Items.Insert(0, new ListItem("-- Select Name --", "0"));
    ddlName.Items.Insert(1, new ListItem("Ajay Gangwar", "1"));
    ddlName.Items.Insert(2, new ListItem("Shashank Tripathi", "2"));
    ddlName.Items.Insert(3, new ListItem("Heena Nautiyal", "3"));
   }

Note : Do not forget to call this method on Page_Load().


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindNames();

        }
    }