Monday 15 September 2014

Difference Between Pass by reference and pass reference Type

(1)
 void Fun(int[] Arr)
    {
        Arr[0] = 888;  // This change affects the original element.
        Arr = new int[5] {-3, -1, -2, -3, -4};   // This change is local.
                           // Because two different refernece is created 
        System.Console.WriteLine("the first element is: {0}", Arr[0]);
    }
static void Main() 
    {
        int[] arr = {1, 4, 5};
        Fun(ref arr); // Call above method
    }
In this case two reference is created. Ref1 and Ref2 are both are pointed to same object. You can change Reference point object by "New" Keyword.
(2)

 static void Fun(ref int[] Arr) {
   // Both of the following changes will affect the original variables:
    Arr[0] = 888;
     Arr = new int[5] {-3, -1, -2, -3, -4};
     System.Console.WriteLine("the first element is: {0}", pArray[0]);
   }
 static void Main() {
     int[] arr = {1, 4, 5};
      Fun(ref arr);
}
Above case only one reference is created. "New" keyword is 
change original object.





Method override interview question in C#

class myClass
    {
        public void myFun(out int a) // ERROR
        {
            a = 10;
        }
        public void myFun(ref int a)
        {
            a=20;
        }
  }
Error:- Cannot define overloaded method 'myFun' because
it differs from another method only on ref and out. And Ref and Out
used Pass by reference for parameter Passing.


You can't use the ref and out keywords for the following kinds of methods:
  • Async methods, which you define by using the async modifier.
  • Iterator methods, which include a yield return or yield break statement.
-----------------------------------------------------------------------------

class myClass
{
 public void myFun(int a)  //No Error
 {
     a = 10;
  }
 public void myFun(ref int a)
 {
    a=20;
  }
 }
-----------------------------------------------------------------------------
void myFun(object x) {}
void myFun(dynamic x) {}//No Error.



Sunday 14 September 2014

Object.gethashcode in c#

A hash code is a numeric value that is used to insert and identify an object in a hash-based collection such as the Dictionary<TKey, TValue> class, the Hashtable class, or a type derived from the DictionaryBase class. The GetHashCode method provides this hash code for algorithms that need quick checks of object equality.

Two objects that are equal return hash codes that are equal. However, the reverse is not true: equal hash codes do not imply object equality, because different (unequal) objects can have identical hash codes.

 class Program
    {
        static void Main(string[] args)
        {
             B obj1 = new B();
            B obj2 = new B();
            Console.WriteLine(obj1==obj2);
            Console.WriteLine(obj1.Equals(obj2));
            Console.WriteLine(obj1.GetHashCode());
            Console.WriteLine(obj2.GetHashCode());
            Console.ReadLine();
        }
    }
    class B:Object
    {
        public override int GetHashCode()
        {
            return 1 ;
        }
        public override bool Equals(object obj)
        {
            return true;
        }
    }
Output:-
False
True
1
1

Here both object has same hashcode. It is not means that it is equal. but if it is two object are same then it has equal hashcode.

Wednesday 10 September 2014

Two interface have same method in C#

Interface I1
    {
        void fun();
        int fun1();
    }
Interface I2
    {
        void fun();
         string fun1();
    }
 class temp : I1, I2
    {
        void fun(){ ......}  // No compile error because two method has same signature,
                                    //Run Time is throw error.
        int fun1(){......}  // Error: we have explicit declare both methods
     }

             


Tuesday 19 August 2014

trancate string in CSS if it goes out of the parent content?

.myClass 
{
    overflow: hidden;         // hide the string if it is overflow.
    text-overflow: ellipsis;  //put three dot after trancate string.
}

Thursday 14 August 2014

Inline switch case in SQL

CASE ISNULL(upub.SharedBy,0) //ISNULL -if value is null then convert to 0.
       WHEN 0  // true when upub.SharedBy=0
            THEN pub.PublicationDate
            ELSE  upub.DateUpdated
 END

Tuesday 5 August 2014

Features of Jquery

Features of Jquery 
1. One can easily provide effects and can do animations. 
2. Applying / Changing CSS. 
3. Cool plugins. 
4. Ajax support 
5. DOM selection events 
6. Event Handling 


and many more other feature provide by jquery.

difference between e.preventDefault(); and return false

The difference is that preventDefault will only prevent the default event action to occur, i.e. a page redirect on a link click, a form submission, etc. and return false will also stop the event flow.

Tuesday 1 July 2014

Attach data of any type to DOM elements in Jquery.

The .data() method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks.


$( "div" ).data( "foo", 52 );
$( "div" ).data( "bar", { myType: "test", count: 40 } );
$( "div" ).data( { baz: [ 1, 2, 3 ] } );
$( "div" ).data( "foo" ); // 52
$( "div" ).data(); // { foo: 52,  // bar:{ myType: "test", count: 40 }, // baz: [ 1, 2, 3 ] } Example:
<body>
<div>
The values stored were
<span></span>
and
<span></span>
</div>
<script>
$( "div" ).data( "test", { first: 16, last: "pizza!" } );
$( "span:first" ).text( $( "div" ).data( "test" ).first );
$( "span:last" ).text( $( "div" ).data( "test" ).last );
</script>
</body>
Output:The values stored were 16 and pizza!

Monday 30 June 2014

How to redirect one page to other in Asp.Net MVC 4?



window.location.href example: window.location is object that holds all information about current document location (host, href, port, protocol etc.). location.href is shorthand for window.location.href.They acting the same when you assign url to them - this will redirect to page which you assing, but you can see difference between them, when you open console (firebug, of developer tools) and write window.location and location.href

window.location.href = '@Url.Content("~/HTML/BrowserNotSupported.html")'; //Will take you to BrowserNotSupported.html.

window.open() example:

window.open('http://www.yahoo.com'); //This will open yahooin a new window.

Thursday 26 June 2014

when should you use “with (nolock)” in SQL?

WITH (NOLOCK) is the equivalent of using READ UNCOMMITED as a transaction isolation level. So, you stand the risk of reading an uncommitted row that is subsequently rolled back, i.e. data that never made it into the database. So, while it can prevent reads being deadlocked by other operations, it comes with a risk. In a banking application with high transaction rates, it's probably not going to be the right solution to whatever problem you're trying to solve with it IMHO.

How to apply CSS on Hidden Button in HTML

CSS file:--
#btnPost[disabled="disabled"] {
    background: none;
}

html file:-
<button type='submit' class='leftArrow' id='btnPost' disabled='disabled'>Post</button>

This css file is used to remove the backgraound of the button.

How to create Widget in JQUERY..

(function ($) {

    $.widget('AZ.azAddNewDiscussion', $.AZ.Node, {
        options: {
          data: null      
        },
        widgetEventPrefix: $.AZ.Node.prototype.widgetEventPrefix,

        _create: function () {               // create event
            this._addNewDiscussion();

            this._on(this.element, {
                'click': function (event) {              
                },
                'click #newDiscussionNode': function (event) {
                    alert('button click');
                }

            });
        },
        _addNewDiscussion: function () {
     
          var buttonElemet = $("<h6 id='newDiscussionNode' style='text-align: right;color: #FFFFFF;margin-right: 1em;'>New Discussion</h6>");
          $(this.element).append(buttonElemet);

        }

    });

})(jQuery);

How to add and remove attribute in JQuery..

Html tag :-
<button type='submit' class='leftArrow' id='btnPost' disabled='disabled'>Post</button>

Remove attribute in jquery--
 $('#btnPost').removeAttr("disabled");

Add attribute in jquery--
 $('#btnPost').attr("disabled", "disabled");

Tuesday 24 June 2014

Apply CSS depending on Input Type and Element type.

CSS file...

.upload-modal input[type="text"], textarea {

border-color: #DDDDDD;
border-style: solid;
border-width: 1px;
display: block;
font-family: roboto;
font-size: 0.9em;
margin: 0.5em 0;
padding: 0.5em 0;
resize: none;
width: 100%;
border-radius: 0.5em 0.5em 0.5em 0.5em;
-moz-border-radius: 0.5em 0.5em 0.5em 0.5em;
-webkit-border-radius: 0.5em 0.5em 0.5em 0.5em;
}

HTML file...
<div class="modal-dialog upload-modal">// two class is apply
<section>
<div class="secChild">
<input name="post" id="post" value="post" type="text">
</div>
<div class="secChild">
<textarea name="description" id="description">description</textarea>
</div>
<div class="secChild">
<input name="tag" id="tag" type="text" value="tag">
</div>
</section>
<div >
Apply above css depending on the element type and input type of all element of upload-modal .

Sunday 15 June 2014

two way add the ajax file into ASP.NET MVC 4


1. @Scripts.Render("~/bundles/jqueryval") into _Layout.cshtml file
2. <script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>--into current excution file

Wednesday 4 June 2014

Difference between Redirect and Transfer in ASP.NET

Response.Redirect should be used when:
  • we want to redirect the request to some plain HTML pages on our server or to some other web server
  • we don't care about causing additional roundtrips to the server on each request
  • we do not need to preserve Query String and Form Variables from the original request
  • we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)
Server.Transfer should be used when:
  • we want to transfer current page request to another .aspx page on the same server
  • we want to preserve server resources and avoid the unnecessary roundtrips to the server
  • we want to preserve Query String and Form Variables (optionally)
  • we don't need to show the real URL where we redirected the request in the users Web Browser