Saturday, January 22, 2011

C # : Difference between Value Type and Reference Type

what is a reference type?

In .NET or in particular in C# there are two main sorts of type: reference types and value types.There is generally a lot of confusion between these two types. Here's a quick explanation:
A reference type is a type which has as its value a reference to the appropriate data rather than the data itself. For instance, consider the following code:
StringBuilder strb1 = new StringBuilder();
 
 Here, we declare a variable strb1, create a new StringBuilder object, and assign to strb1 a reference to the object. The value of strb1 is not the object itself, it's the reference. Assignment involving reference types is simple - the value which is assigned is the value of the expression/variable - i.e. the reference. This is demonstrated further in this example:
StringBuilder strb2 = new StringBuilder();
StringBuilder strb3 = strb2;
 
Here we declare a variable strb2, create a new StringBuilder object, and assign to strb1 a reference to the object. We then assign to strb3 the value of strb2. This means that they both refer to the same object. They are still, however, independent variables themselves. Changing the value of strb2 will not change the value of strb3 - although while their values are still references to the same object, any changes made to the object through the sbrb2 variable will be visible through the strb3 variable. Here's a demonstration of that:
StringBuilder strb2 = new StringBuilder();
StringBuilder strb3 = strb2;
strb2.Append ("String");
strb2 = null;
Console.WriteLine (strb3);
 
 Output:
String
 
Here, we declare a variable strb2, create a new StringBuilder object, and assign to strb2 a reference to the object. We then assign to strb3 the value of strb2. We then call the Appendstrb2 variable. After this, we set the strb2null (a value which doesn't refer to any object). Finally, we print out the results of calling the ToString method on the StringBuilder object via the reference held in the strb3"String" is displayed, demonstrating that even though the value of strb2 has changed, the data within the object it used to refer to hasn't - and strb3 still refers to that object. method on this object via the reference held in the variable to variable.
Class types, interface types, delegate types and array types are all reference types. 

what is a value type?

While reference types have a layer of indirection between the variable and the real data, value types don't. Variables of a value type directly contain the data. Assignment of a value type involves the actual data being copied. Take a simple struct, for example:
public struct struct1{
public int i;
}
 
Wherever there is a variable of type struct1, the value of that variable contains all the data - in this case, the single integer value. An assignment copies the value, as demonstrated here:
struct1 one = new struct1();
one.i=10;
struct1 two = one;
struct1.i=11;
Console.WriteLine(two.i);
 
 Output:
10
 
Here, two.i has the value 10, because that's the value one.i has when the assignment two=one occurs - the values in two are independent of the values in one apart from when the assignment takes place.  
Simple types (such as float, int, char), enum types and struct types are all value types.
Note that many types (such as string) appear in some ways to be value types, but in fact are reference types. These are known as immutable types. This means that once an instance has been constructed, it can't be changed. This allows a reference type to act similarly to a value type in some ways - in particular, if you hold a reference to an immutable object, you can feel comfortable in returning it from a method or passing it to another method, safe in the knowledge that it won't be changed behind your back. This is why, for instance, the string.Replace doesn't change the string it is called on, but returns a new instance with the new string data in - if the original string were changed, any other variables holding a reference to the string would see the change, which is very rarely what is desired. 
Constrast this with a mutable (changeable) type such as ArrayList - if a method returns the ArrayList reference stored in an instance variable, the calling code could then add items to the list without the instance having any say about it, which is usually a problem. Having said that immutable reference types act like value types, they are not value types, and shouldn't be thought of as actually being value types.

Wednesday, December 22, 2010

Windows Phone 7


Microsoft took the wraps off of Windows Phone 7 Series (the official name for Windows Mobile 7s) which is a complete overhaul from previous versions of the OS...Slick, Touch-Friendly User Interface.

The Quick Launch screen is a far-cry from the old Windows Mobile start screen. Large, colorful tiles serve as shortcuts to your most-used or favorite apps or Web sites. You can also place live tiles on the screen with links to your Facebook profile or friends.

These tiles are live, meaning if the content of the app or site is updated, the tile will update on your screen. So if you have a link to a friend's Facebook profile on your Quick Launch screen, that tile will update when they change their picture. It is a bit creepy if you don't know them very well, but cool nonetheless.

The People Hub aggregates you friends from all of your social networks in three screens: Recent, All, What's New

If you're an Xbox owner and want to keep tabs on your friends' achievements, Windows 7 phones will come with a mobile version of Xbox Live . Users will also be able to purchase games and apps easily from the Windows Marketplace as well.

According to Microsoft, hardware partners will not be able to replace the Windows 7 UI.

Microsoft is also taking further control over the hardware side. All Windows Series 7 phones will ship with three hardware buttons: Home, Search, and Back. They'll also all be capacitive touch-enabled with multitouch.

Tuesday, December 21, 2010

The Previous year....

Its been a year and 2 months since i have joined infosys and the previous year had been a year where i have experienced a lot of things.

Starting with the infy's training..the Mysore campus was really a once in a lifetime experience as it look liked to us for the first weekend :)

We explored the campus and enjoyed all the facilities provided to us, but then something happened during the third week..our technical training started with modules exams going to come every weekend and course divided into basic,intermediate and stream level.

I enjoyed studing all the subjects taught to us till the streams but one thing i hated about the training..we were overloaded with the modules. As our batch was a non cs/it on...most of us found it difficult to cope with the modules burden..resulting in studies that ended at 12 everyday..when the GEC-2 ,our study center got closed.

I resist studying in boundations...you cannot gain in depth knowledge by studying modules like unix in 4 days... i love exploring all the things during the technical reading.. :P . Among all the exams ....handson were comparatively the better ones and ILI sessions were a refreshing experiences.

During streams most of us got a good schedule for the day...with sqaush,pool,swimming,movies and gyming going in sync with the module studies.Post projects were the easiest phase of our 5 months training and we enjoyed a lot during this time.And Finally we got are postings ....a total "go haywire" situation...there were deals going on between trainees...with their posting on stake :) .Most of us got Chandigarh with our project allocated to testing unit...having no ideas about testing we were happy at that time..till...

Will continue this in my next post :)

Back to blogger

Finally after a long pause i decided to keep in touch of blogger again :) . Last year before the infy's training started , i was really into blogging. I hope i would write something original and something worth reading :)

Thursday, October 22, 2009

Pay It Forward....



I was totally confused yesterday ..... i was going to download my last movie till training that i would be watching on my laptop.... before leaving.. :P
well after searching a lot on google a decided to dL this movie "pay it forward"..

Heres the torrent -

Well to my atmost surprise the movie was actually an awesum one..

A film of surprising majesty mainly because of its sincerity to convey the tale of a young high school student who comes up with a beautiful and simple plan to make a difference in the world, involving doing a good turn to not just one person but three, who then, in turn, return the gift themselves to three more people, thereby very quickly spreading goodness in both directions, in the giving and receiving, in the most unlikely places and ways.
Well i think the image will explain everything...

Thus i do think that in our world helping other people is perhaps the most important we can do. Children are the ones who often teach us how to behave in certain unpleasant circumstances. It is not only a moving story but everybody who sees this film stops for a moment or more and think over the meaning of life.

So i think i have talked a lot about high values now.... :P but definitely i am going to continue watching such good movies... and doing good deeds.... :)

Thursday, September 17, 2009

Be yourself & selfless : Road to inner peace

I often find people complaining about their life and are very much dissatisfied with their present living.
The most common problem that i believe is always expecting much more from people around us.
I always believe that nothing is wrong with dreaming bigger.Dreams give us hope but most of us have limited our dreams to materialistic things which makes us really worried about getting things which may be not very useful to them but just a passtime.
In my opinion life is always about giving.We must praise things what we have right now with us and should be doing things that really make other people life happier.
Well upto some extent if a person really wants some thing big,he or she should strive hard to get it (not expecting it from others) ,then only our life would be filled with great pleasure and inner peace.I really think that if half of the population in world starts believing in giving ,world will be soon a great place to live in for everyone.

"Keep your dreams in line of vision and always be willing to do the work and the work will be meaningful and fulfilling. "

Secondly most people are other people. Their thoughts are someone else's opinions, their lives a mimicry.They always pretend to be like other people,may be to get in a friend circle or to get a loved one etc etc. God has given you one face, and you make yourself another.I saw a movie recently (Juno) and a quote from it exactly fits here-

"The best thing you can do is find a person who loves you for exactly what you are. Good mood, bad mood, ugly, pretty, handsome, what you have. That's the kind of person that's worth sticking with. "

Wednesday, September 9, 2009

Google hacks : Speed up your searching with preciseness on Google Search Engine

Speeding up your search on Google Search Engine:

Well nowadays most of use google generally as his/her search engine.Many a times while searching you might be experiencing problems with results you get from the google.
Well a little knowledge of some hacks can save you a lot of time ,in exact terms "what you want to search exactly".
Google being a full-text search engine, it indexes entire web pages instead of just titles and descriptions. Additional commands, called special syntaxes, let Google users search specific parts of web pages or specific types of information. This comes in handy when you're dealing with 2 billion web pages and need every opportunity to narrow your search results.

Now i am going to tell you some hacks might be useful for you while searching -

(1) intitle:
intitle: restricts your search to the titles of web pages. The variation, allintitle: finds pages wherein all the words specified make up the title of the web page. It's probably best to avoid the allintitle: variation, because it doesn't mix well with some
of the other syntaxes.

intitle:"Wallpapers"
allintitle:"money supply" economics

(2) inurl:
inurl: restricts your search to the URLs of web pages. This syntax tends to work well for finding search and help pages, because they tend to be rather regular in composition.An allinurl: variation finds all the words listed in a URL but doesn't mix well with some other special syntaxes.

inurl:help
allinurl:search help

(3) intext:
intext: searches only body text (i.e., ignores link text, URLs, and titles). There's an
allintext: variation, but again, this doesn't play well with others. While its uses are
limited, it's perfect for finding query words that might be too common in URLs or link titles.

intext:"yahoo.com"
intext:html

(4) inanchor:
inanchor: searches for text in a page's link anchors. A link anchor is the descriptive text of a link. For example, the link anchor in the HTML code "linux forum " is "linux question's user".

inanchor:"anandjss"

(5) site:
site: allows you to narrow your search by either a site or a top-level domain AltaVista, for example, has two syntaxes for this function (host: and domain:), but Google has only the one.
site:loc.gov
site:edu


(6) link:
link: returns a list of pages linking to the specified URL. Enter
link:www.google.com and you'll be returned a list of pages that link to Google.

(7) cache:
cache: finds a copy of the page that Google indexed even if that page is no longer available at its original URL or has since changed its content completely. This is particularly useful for pages that change often.

cache:www.yahoo.com


(8) daterange:
daterange: limits your search to a particular date or range of dates that a page was
indexed.Remember also that Google reindexes pages. Whether the date range changes depends on whether the page content changed. For example, Google indexes a page on June 1.Google reindexes the page on August 13, but the page content hasn't changed. The date for the purpose of searching with daterange: is still June 1.

(9) filetype:
filetype: searches the suffixes or filename extensions.Google indexes several different Microsoft formats, including: PowerPoint (PPT), Excel (XLS), and Word (DOC).

filetype:pdf "Jssaten"


(10) related:
related: as you might expect, finds pages that are related to the specified page. Not all pages are related to other pages.

related:www.cnn.com

(11) info:
info: provides a page of links to more information about a specified URL. Note that this information is dependent on whether Google has indexed that URL or not.

info:www.nytimes.com/technology

(12) phonebook:
phonebook:, as you might expect, looks up phone numbers.

phonebook: Anand srivastava


plz try this you can really save a lot of time while searching any particular file or person so easily on google.
Have fun :)