Thursday, January 25, 2018

Constant and Fields

Constant 


Constant is a symbol,  the value of which is never changed. As it's value is assigned at compile time so, the compiler saves the constant value in assembly metadata.

Constant can only be of primitive type  i.e; Boolean, Char, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, Decimal and String.
One exception to above is that you can have constant of non-primitive type but with value as null.
e.g; public const MyClassType ClassConst = null;

Constants are implicitly static members.

Whenever a constant is called, compiler search for it in the assembly metadata where constant is defined and embed the constant value in the intermediate Language (IL) of caller code.

For Constant no memory is required at run time as it's value is already embedded in the code. Which means that constants have no address and can't be passed as reference.
Also,  because of the embedding versioning of constants are not possible.

Fields


It's a data member that holds the instance of a value type or reference of a reference type.
Fields are stored in memory, so,  there value can be read,  write or updated at run time.

Versioning is possible with fields and variables need not to be of primitive data types as constants.

The modifiers that can be used with fields are:
  • Static
  • Instance type (default) 
  • Readonly
  • Volatile 

Readonly Fields
  • The value can only be altered in the constructor. 
  • Reflection can be used to change fields value 
  • If the field is of reference type and readonly, the reference is immutable and not the object field refers to. 


Friday, January 19, 2018

Delegates

Before understanding Delegates, we first need to understand two concepts.
  1. Covariance:- A method can return a type that is derived from the delegate's return type.
  2. Contra-variance:- A method can take a parameter that is a base of delegate's parameter type.
Note: Covariance and Contra-variance are supported only for reference types and not for value types or for the void. Because memory structure for value types and void varies, whereas, the memory structure for the reference type is always a pointer.


  • Delegates ensure that the callback method is type-safe.
  • Delegates also integrate the ability to call multiple methods sequentially and calling of static methods as well as an instance method.

When we define a delegate compiler internally creates a complete class for that delegate

internal delegate Int32 PrintString(Int32 value);

internal class PrintString: System.MulticastDelegate
{
        //constructor
       public PrintString(Object @object, IntPtr method);

    //Method with the same prototype as specified by the source code.
   public Int32 Invoke(Int32 value)
   {
        Int32 result;
       Delegate [] delegateSet = _invocationList as Delegate[];
   
      if(delegateSet != null){
          foreach(PrintString p in delegateSet)
                result = d(value);
     }
     else {
            //The delegate identifies a single method to be called back
            // Call the callback method on the specified target object.
             result = _methodPtr.Invoke(_target, value);
        }
   }
    return result;
}
  • Delegates can wrap calls to instance methods as well as static methods. For instance methods, the delegate needs to know the instance of the object the method is going to operate on.
  • Delegate types can be defined within a type (nested within other types) or at a global scope. Basically, because delegates are classes, a delegate can be defined anywhere a class can be defined.


Delegate Chain

Delegate.Combine (+=) adds delegate object to the delegate chain.
Delegate.Remove(-=) removes delegate object from the delegate chain.

eg. PrintString psString1 = new PrintString(Program.PrintToConsole);

      PrintString psStringChain = (PrintString)Delegate.Combine(psStringChain, psString1)
   
      PrintString psStringChain = (PrintString)Delegate.Remove(psStringChain, psString1)

PrintString psString1 = new PrintString(Program.WriteToConsole);
PrintString psString2 = new PrintString(Program.WriteToCloud);
PrintString psString3 = new PrintString(new Program().WriteToFile);

PrintString psChain = null;


1) psChain += psString1;



2) psChain += psString2; (A new delegate object is created)



3) psChain += psString3;


4) psChain -= psString3;

When Remove(-=) is called, it scans the delegate array (from the end towards index 0).
A) If a match found and there is only one item left in the array, that array item is returned.

B) If a match found and there are multiple items left in the array, a new delegate object is created - the _invocationList array created and initialized will refer to all items in the original array except for the item being removed, and a reference to this new delegate object is returned.

C) If you are removing the only element in the chain, Remove returns null.

Note:- Each call to Remove removes just one delegate from the chain, it does not remove all delegates that have matching _target & _methodPtr fields.

GetInvocationList() --> Operates on a Multicast delegate and returns an array of Delegate reference where each reference points to one of the chain's delegate object

Thursday, January 18, 2018

Life is what you make it - Reena Shennoy

In her book book "Life is what you make it"  Reena narrated a story of a girl named Ankita who was very intelligent and was very good in writing and painting.
The girl had seen so much of ups in her life but just after 6 months of joining MBA she became the patient of bipolar disorder and was not able to do anything.  She was not able to read and remember two sentences. After going to many psychiatrist she finally got a good doctor named as Dr. Madhusudan who helped her in recovering.  He was the one who actually made her realize that:

One should do what makes one happy and should continue with that. 

After this Ankita left her MBA and joined writing and painting courses and become very successful. 

Sunday, October 16, 2011

Online Dating


Online Dating is a very popular and online way of making new relationship via communicating with thousands of people of their interest.

It is a new way of making romantic or sexual liaison without first congregate with each other.

Some people are first fright about online dating as you are going to share your information with thousands or millions of people on the website, but once they do it, they find it very helpful. Many people found their life partners from these websites and they are very happy.

Everything has its own pros and cons same is the case with Online Dating, one side many people found their life partners but on its back side many people are being ditched on these sites. You are sharing all your information with many people so sometimes people can take extra benefits of yours. Many a times some married people seeks for extra marital affairs, some people tells a lie about themselves to trap the people, sometimes people misuse your snaps as nobody predicts the human mind. Even after all these problems all the dating websites are full of users.

If one is really serious about finding a partner on the online dating website then he/she should be very careful and specific about their profile. Your profile speaks for you there. Any one before chatting or mailing you will read your profile and most of the times people do not care about this.

When you are on the dating website you should take care of few things:
1.      Whenever you chat with any person talk to him on the things or topics you want your partner should have or should be good into them.
2.      While putting a snap on the dating website he/she should bear in mind that you should put a snap which is solely yours. Otherwise, sometimes it may create problems not only for you but for your friend(s) or family member(s) like; people may get interested in your friend instead of you. So, it is better if you put a snap which is.
3.      Whenever on the chatting site people are tend to start chatting with the members. First, filter out the people with different search criteria given on the website and then try to contact them via email or by private messaging. Many people those who are just doing time pass there will not reply you. So, by this you have one more kind of auto filtering.

Dating websites offer many services like broadcasting, online chat and message boards etc. Some gives you free registration but to search for premium members you also need to be a premium member.
So, when you are going to find a partner from any online dating website please take care of all the above mentioned things.

Sunday, October 2, 2011

Link wheel service

In the pursuit of improving the search engine ranking, webmasters and SEO experts use different SEO techniques to improve there website ranking in this the link wheel service is one of the technique which if used intelligently will increase the website ranking. It is a concept for enhancing the website ranking.

Link Wheel as its name suggests “A Wheel of Links” i.e; a chain of links which are linked to each other and finally to the main website.

Link wheel service can be achieved by many ways like by linking the articles to each other and finally to the main site or by giving links. In SEO Back link is very frequently used and is a very valuable technique so using that we create link wheel i.e. a complete chain/wheel of Back links. Random Back links are also a good technique to attain the link wheel.

Link wheel is a White Hat technique but it should be used intelligently and carefully and if you are using multiple link wheel services than you need to be very specific and should randomize your links so that it will be counted differently by the GOOGLE otherwise it might be discounted which will not increase your website ranking which will be a loss of your efforts.

The Link Wheel service as well increase the ranking of your other websites as when you link different pages of different sites of yours the user’s will also visit your other websites as well and more hits on your website also increase the popularity of your other websites too, though you can also publish your website links on others website too.

Now when we link our different articles with one another then in that case search engines will give them more regard than in case of unlinked articles. Always, remember if you are linking your articles then they should be relevant otherwise it will create a fuss in the mind of the reader and might frustrate the user/reader. Though it takes some time to create a Link Wheel as you need to write good articles or pages to link but this pays you a lot once you are done with it.

So, if you want to give your website a better ranking let’s give a try to Link Wheel service and check out the results of your own.