0

Clear an Array in c#


string[] arr = new string[4];
arr[0] = "000";
arr[1] = "111";
arr[2] = "222";
arr[3] = "333";
 
Array.Clear(arr, 0, arr.Length);

0

How to use Stopwatch in C#


Create an object of Stopwatch class and start it, then execute the method, logic whose execution time is to be calculated. Next stop the watch shown below.

Stopwatch watch = new Stopwatch();
watch.Start();           

for (int i = 0; i < 100000; i++)
{
   for (int j = 0; j < 20000; j++)
   { 
                    // To waste some time....:P
   }
}
watch.Stop();
double time_wasted = watch.Elapsed.TotalSeconds;
// To round 
double time_wasted_rounded = Math.Round(watch.Elapsed.TotalSeconds);
0

How to limit decimal places in double


Here I am limiting the decimal places to 3 in a double.
 
 double old_value = 3.142356;
 double new_value = Math.Round(old_value, 3);
:)
0

How to block a website

1.       Open Run, and type in ‘C:\Windows\System32\drivers\etc’, press enter. A folder should open up with the following contents.

2.       From the above files, open the “hosts” file using a notepad. The following is how the contents of this file should appear.

Now we will have to edit this “hosts” file, so as to block certain sites, which in this scenario are
 1. Yahoo.com and
 2. Bing.com.
The following changes are required for the same…


3.       Now try opening these websites using any of the browsers. The site will not open instead an error message will be shown. You can block any number of websites using this method.



Cheers!
6

Create Horizontal Menu Bar using HTML and CSS


Following is a simple demonstration of how to get a horizontal menu bar using HTML (using <ul> / <li>) and CSS.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>Sample by Yasser.</title>
  <style type="text/css">
.hovermenu ul{
fontbold 18px calibri;
height25px;
}

.hovermenu ul li{
list-stylenone;
displayinline;
}

.hovermenu ul li a{
padding10px 25px 10px 25px;
text-decorationnone;
floatleft;
colorwhite;
background-colorrgb(15,41,77);
border1px solid rgb(15,41,77);
}

.hovermenu ul li a:hover{
background-color#e5e5e5;
color:rgb(15,41,77);
}
</style>
 </head>

 <body>

<div class="hovermenu">
<ul>
<li><a href="">Menu1</a></li>
<li><a href="">Menu2</a></li>
<li><a href="">Menu3</a></li>
<li><a href="">Menu4</a></li>
<li><a href="">Menu5</a></li>
</ul>
</div>

</body>
</html>

Expected Output:

 Cheers!
0

How to do SELECT TOP @Param in a Stored Procedure?

 How to do SELECT TOP @Param in a Stored Procedure? 

Here I have created an integer param which is used later in the SELECT statement.

CREATE PROCEDURE [dbo].[SP_get]
@my_param int   
AS
BEGIN
      SET NOCOUNT ON;

SELECT TOP (@top_param) col1, col2, col3
      FROM TableName 
0

An unsecured or incorrectly secured fault was received from the other party


An unsecured or incorrectly secured fault was received from the other party

This error normally occurs when the Time Zone of the server and the client are different.
The remote server and the client's system time must be within 10 minutes of each other.
Solution 1:
So One Temporary solution was to change the TimeZone as well as the Time to the time currently on the server.
Solution 2:
Was to include the following security node under the binding of custom binding element.
<security authenticationMode="Kerberos">
   <localClientSettings maxClockSkew="00:07:00" />
   <localServiceSettings maxClockSkew="00:07:00" />
   <secureConversationBootstrap>
      <localClientSettings maxClockSkew="00:30:00" />
      <localServiceSettings maxClockSkew="00:30:00" />
   </secureConversationBootstrap>
</security>
0

Read specific nodes from an XML File

The following article discusses how to read an XML file. 
The sample XML file that i have used is also attached below.
I have used XmlTextReader for reading. 
The   while (reader.Read()) return true until all the nodes of the document are read. 
reader.ReadToFollowing("repeat_element");
is used to jump to the specified node, incase you are not interested in any other node and want to read only that node or its child nodes. 
reader.Name returns the name of the element and reader.ReadString() will return its value/innerText.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace sample
{
    class Xml_Reader
    {
        FileStream fileStream;
        string fileName = string.Empty;
        static int count = 0;
        
        public void Read()
        {
            fileName = @"D:\Yasser Files\sample.xml";
            fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            string temp_variable = "";

            using (XmlTextReader reader = new XmlTextReader(fileStream))
            {
                // To jump to the node where we want to begin our search from.
                reader.ReadToFollowing("repeat_element");

                while (reader.Read())
                {
                    if(reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                            case "interested_element1":
                                {
                                    temp_variable += "--"+ reader.ReadString();
                                    break;
                                }
                            case "interested_element2":
                                {
                                    temp_variable += "--" + reader.ReadString();
                                    break;
                                }
                            case "interested_element3":
                                {
                                    temp_variable += "--" + reader.ReadString();
                                    break;
                                }
                            case "interested_element4":
                                {
                                    temp_variable += "--" + reader.ReadString();
                                    break;
                                }
                            case "interested_element5":
                                {
                                    temp_variable += "--" + reader.ReadString();
                                    break;
                                }
                        }//end of switch
                    }//end of if loop.
                }//end of reader.
            }
        }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<myroot>
  <repeat_element>
    <nt_interested_element1>aa</nt_interested_element1>
    <interested_element1>yasser</interested_element1>
    <nt_interested_element2>cc</nt_interested_element2>
    <interested_element2>sachin</interested_element2>
    <nt_interested_element3>eee</nt_interested_element3>
    <interested_element3>sehwag</interested_element3>
    <somelevel>
      <somelevelDown>
        <deep>
          <interested_element4>dhoni</interested_element4>
          <interested_element5>raina</interested_element5>
        </deep>
      </somelevelDown>
    </somelevel>
  </repeat_element>
  <repeat_element>
    <nt_interested_element1>11</nt_interested_element1>
    <interested_element1>ramesh</interested_element1>
    <nt_interested_element2>33</nt_interested_element2>
    <interested_element2>suresh</interested_element2>
    <nt_interested_element3>55</nt_interested_element3>
    <interested_element3>sonu</interested_element3>
    <somelevel>
      <somelevelDown>
        <deep>
          <interested_element4>monu</interested_element4>
            <interested_element5>ronu</interested_element5>
        </deep>
      </somelevelDown>
    </somelevel>
  </repeat_element>
</myroot>

 

2011 ·Code-Studio by yrus.