Thursday, 9 May 2013

Return anonymous type from function


private object AB()
{
  return new { A = 10, B = "ac" };
}
private dynamic AB1()
{
  return new { A = 10, B = "ac" };
}
public static T Cast<T>(object obj, T type)
{
  return (T)obj;
}

protected void Button1_Click(object sender, EventArgs e)
{
  var c = new { A = 0, B = "a" };
  var v = Cast(AB(), c); // Using Object dataType
  string b = v.B;
  var s = AB1();  // Using Dynamic dataType
  string a = s.A;                      
}

Extension Method in C#


  


protected void Button1_Click(object sender, EventArgs e)
{
            string a ="AP";
            a.DoChange("A", "P");
    
       //it will retun  APAPAjay
}
 
public static class TestExtension
{
  public static string DoChange(this string x, string a,string B)
  {
     return x + a + b + "Ajay";
  }
}

Get List of computers connected in LAN


using System.Net.NetworkInformation;

List<string> IP = new List<string>();
private void button1_Click(object sender, EventArgs e)
{
   Ping obj = new Ping();
   for (int i = 0; i < 255; i++)
   {
     try
     {
      PingReply objreply = obj.Send("192.168.0." + i.ToString());
      if (objreply.Status != IPStatus.DestinationHostUnreachable)
       {
          IP.Add(objreply.Address.ToString());
          IP.Add(Dns.GetHostByAddress(objreply.Address).HostName);
       }
     }
     catch
     {
     }
   }           
   ListBox.DataSource = IP;
}


 

Wednesday, 10 April 2013

Simple image Slider in Jquery


JS

Use JQuery and Jquery.ui

$(window).load(function () {
            var v = $("img");
            setInterval(function () {
                $('#dvContain :nth-child(1)').next()
   .show("bounce",  500)
   .end()
   .hide("explode", 1000)
   .appendTo('#dvContain');
            }, 2500);

        });

CSS
   <style type="text/css">
        #dvContain
        {
            height: 200px;
            width: 300px;
            overflow: hidden;
            padding: 0;
        }
       
        #dvContain img
        {
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }
        #dvContain img.firstslide
        {
            display: block;
        }
    </style>

HTML
<div id="dvContain">
           <img src="Images/Chrysanthemum.jpg" width="300" height="200"   
                     class="firstslide" />
            <img src="Images/Desert.jpg" width="300" height="200" />
            <img src="Images/Hydrangeas.jpg" width="300" height="200" />
            <img src="Images/Jellyfish.jpg" width="300" height="200" />
  </div>