Two uses of using keyword in C#
Most of the C# interviewers will attempt to ask this question:
What are the uses of using keyword?
There are two uses of using keyword in C#
1) Using as Directive in C# can be used for importing namespaces to your classes. Everybody knows this.
2)Another most useful advantage is it can be used in codeblocks what is does is it calls the Dispose() method automatically to release the resources and also automatically implements the try catch blocks for you.Here it is called a using statement.So the advantage is that we dont have to explicitly write a try-catch block and our code looks small.
What is the definition behind atoi()?
Here is the C# code for the definition of atoi()
static int atoi(string str)
{
int sign=1;
int Number=0;
int tmp=0;
int x=0;
int l=(str.Length)-1;
char[] c=str.ToCharArray();
if ('-'==c[0])
{
sign=-1;
x=1;
}
for(;x ='0')&&(c[x]<='9'))
{
//0 is the 0 index
tmp=(c[x]-'0');
//simply multiply the number by 10 and add it
Number=Number*10 + tmp;
}
}
return Number*sign;
}
Just for fun!
C# Function Parameter Passing by Reference in Detail
Here are is a simple test to play with the function parameter passing in C#.
As you guys know int, float, char, enum and struct are value types and class is a reference type.
In case of C#, lot people think objects are passed by reference to a function, but the reality is object references are passed by value.
How to prove it? Here is the code. Analysis of the code is below so keep reading….
using System;
namespace APP1
{
class Program
{
static void Main(string[] args)
{
Program Test = new Program();
Int first = new Int();
first.i = 6;
Int second = first;
Test.change(ref second);
Console.WriteLine("first: " + first.i);
Console.WriteLine("second: " + second.i);
CInt cfirst = new CInt();
cfirst.i = 6;
CInt csecond = cfirst;
Test.change(ref csecond);
Console.WriteLine("cfirst: " + cfirst.i);
Console.WriteLine("csecond: " + csecond.i);
Console.Read();
}
void change(ref Int param)
{
param= new Int();
}
void change(ref CInt param)
{
param = new CInt();
}
}
public class CInt
{
public int i;
}
public struct Int
{
public int i;
}
}
Here I have a struct Int and a class CInt.
First lets look at the Int struct object and the Change function:
On a normal Change function with out “ref” keyword the console would print 6 for both first and second object.
Here we have a ref and we are trying to initialize the parameter object.
void change(ref Int param)
{
param= new Int();
}
In the Main we are calling
Test.change(ref second);
So the output we get is
first: 6
second: 0
This is the behaviour of struct type you can say it is passed by value.
Now lets come to the Class type:
void change(ref CInt param)
{
param = new CInt();
}
We have the default values set to 6 before the call:
Test.change(ref csecond);
Whet do you think the output will be?
You may think it would have reset both cfirst and csecond to 0, but the reality is
you will get the output as
cfirst: 6
csecond: 0
This is because of the reason the object references are passed by value.
However, if you change any of the class members value
for example if you set on the change function with CInt as parameter with or without “ref” keyword and without initializing the param object.
param.i = 7;
you will notice it will affect the csecond and cfirst (and the output will be 7) which will give you an impression it is infact objects are passed by references.
The only way to track the behaviour of object references are passed by value is by trying to initializing the parameter inside the function.
I hope this helps you understand the parameter passing in C#.
If you have any questions or comments please reply here.
Received a Forwarded Mail on Store Closings
Stores that are planning to close after Christmas are still selling gift cards through the holidays even though the cards will be worthless January 1. There is no law preventing them from doing this. Below is a partial list of stores that you need to be cautious about.
Circuit City (filed Chapter 11)
Ann Taylor 117 stores nationwide closing
Lane Bryant, Fashion Bug ,and Catherine’s to close 150 stores nationwide
Eddie Bauer to close stores 27 stores and more after January
Cache will close all stores
Talbots closing down specialty stores
J. Jill closing all stores (owned by Talbots)
Pacific Sunwear will close its struggling chain of 154 demo stores.
GAP closing 85 stores
Wickes Furniture closing down
Zales closing down 82 stores and 105 after January
Whitehall closing all stores
Piercing Pagoda closing all stores
Disney closing 98 stores and will close more after January.
Home Depot closing 15 stores 1 in NJ ( New Brunswick )
Macys to close 9 stores after January
Linens and Things closing all stores
Movie Galley Closing all stores
Pep Boys Closing 33 stores
Sprint/Nextel closing 133 stores
JC Penney closing a number of stores after January
Ethan Allen closing down 12 stores.
Wilson Leather closing down all stores
K B Toys closing 356 stores
Loews to close down some stores
Dillard’s to close some stores
Lot of people forgot one more thing, Does any of you pay of the protection plans offered by these stores on electronic items? (which they will tell you that its going to be broken on the day you buy), now you know where these money are gone to when the stores are closed.
All you need a big shop with a very stupid idea and protection plan.
You can stop paying protection plans to Circuit City / Best Buy, because you don’t know even these guys will last till you product does.
It Sucks big time!
Essay Writing on a Indian Cow

What else you want me to write here? This says everything. Don’t miss it.
Magic with the magnetic hands – 5yr old
Some news are mentioning it as crazy, but I don’t think this is crazy, Its a magic with the magnetic hands on non magentic objects by Milan Simon Tuttle, a 5-year-old girl. She rocks with it!
You could see the balls are obeying her instructions very very nicely.
Don’t miss it! Awesome!
Many doctors plan to quit or cut back: survey
Yahoo News: Many doctors plan to quit or cut back: survey
I don’t know, 90% of the time when I go the primary care doctors in new jersey(don’t know about other states):
1. They are always on the phone with somebody else, while i’m on the waiting room or sometimes even they examine me.
2. It will nearly take 1 year for them send us to a specialist, when the disease is out of their lead, sometimes the disease will attempt to leave us.
3. You will get an appointment for 4:30, but you will be checked at 6:00 this is just an average.
4. If you are in a emergency, you will get noticed by a doctor after 10 hours (average and you are lucky) because your vitals are OK.
5. After all this you still pay your co-pay.
At this point of time, I feel I want to say why don’t you guys do your work and stop whining and you don’t even work without a time limit like a specialist does. I think the insurance companies should remove doctors from their network based on the review by the patients and that will get them to work.
This is the lamest thing I’ve ever heard and if the society is going to loose a few quitters, its good for the society, don’t bother about this threat. This is the real right time from them to quit.
Cloud Computing – New Era or removal of freedom
“Cloud Computing is a paradigm in which information is permanently stored in servers on the Internet and cached temporarily on clients that include desktops, entertainment centers, table computers, notebooks, wall computers, handhelds, sensors, monitors, etc.” – From Wiki
There are lot things that can happen with cloud computing, however when I look at this architecture and the way its pushed by Amazon, Google and Microsoft, I personally feel we are closing towards corporating the entire internet and leaving the entire privacy of everybody to these few folks.
Because what ever these guys are talking as cloud computing, in future it has high possibility of losing our PCs and everything become a dumb terminals and what ever you do or don’t do is completely given to these folks and they will charge you with a few cents.
Think about this, today we use individual computing powers to perform some action with lot variety of standalone applications like Text Editors, Spreadsheets and office components and if they become network only under the clouds, what will you be left with? May be a monitor only with a network card.
Already Google has its office component in network only, all they got to add is a price tag to use it for cloud costs May be Microsoft is totally frustrated with piracy issue and the only way they can think of ending this is by making their best to be network enabled or go “live”.
On the positive side, this may be a stepping stone for virtual offices which will allow people to work across the continents and ofcourse everybody’s network will have the same bandwidth power at the cost of your entire personal privacy.
No matter how much legal bindings these guys are going to put in the paper, at the end of the day if your desktop is in a network, you are 100% monitored by some one and they exactly know where to find you simple as it is. Even in today’s world, no one has a true privacy, everybody is being monitored in the name of website visitors etc…
When this succeeds to every single user, we can say its the end of the true internet, however there will be new forms which will arise to counter this… Come on… this is what we are doing for thousands of years, don’t we?
Hampster on a piano…
Here is a nice video the hampster is trying to eat a popcorn, really all it thinks about is to just eat it and having some fun with it…
Have fun!
NJTransit – Way to save Money – Really
If you are living in new jersey and you are commuting to nyc you will know what I’m talking about, even if you are not in this area, its a rail commute system, directly under the NJ Governer.
Well, A communter travelling between MetroPark to Newark Penn or New York Penn stations will have this shared experience every single day.
1. It will be crazy crowded from 6:57 AM to 9:15 AM and 5:25 PM to 7:11 PM. No matter how bigger the train is, Joe the plumber (After the election Average Joe become Joe the Plumber) will never have a seat to sit.
2. Most of the time it will be 10 minutes late to the specified destinations every single day. Nobody is even coming in the opposite direction. A 25 mile ride taking 45 minutes only possible with NJTransit.
3. Crowded with my fellow indians, who just pay and never expect the comfort, because we have the tolerance for the entire world and we always think we were late to get inside the train and we never go to the public hearings of the NJTransit, which happens every quarter I guess, I hardly know.
4. You can visually experience in every single car, 2 people on the two corners on a 3 seater and our average traveler between NYC – Metropark will be the center man who will be late to get out of the train as well… and there will be only one exit out from the platform….so it will be like a festival crowd every single day you are right its metropark, even after the new design while swallows a wopping millions of dollars.
5. If the train is late in the morning by 5 minutes, you will see the festival inside every car, what a life? You are really blessed to have that.
6. Most of the time the conductor will never come to check the passes, even if they come with this crowd, he will never cross more than 2 cars, if he crossed all the cars, then it means, the trains is running really really late either way.
7. Sometimes, they don’t even announce the NEC trains in Newark or Newyork penn they arrive.
8. Its really an expensive trip for a 25 mile ride, with no comfort.
9. Last but no least, Our brilliant indians and chinese always try to get out of the train fast say they virtually calculate the cars and they get closer to the one which will stop closer to the exit to the station from platform, but every single day, our NJTransit drivers, randomly place the cars and ask these folks to walk forward or backwards, by this time, festival is started by the don’t care folks inside the car.
So after seeing all this,
what I thought to save money is passengers between Metropark and Newark/Newyork Penn must avoid buying monthly tickets.
1. They must carry $20 every day and select a random crowded car and ride through, at the end of the day, we don’t get the comfort we need, so if the conductor comes, hand over the $20 and it will surely take 5 minutes for each passenger after using their punch cards for tickets, by 15 minutes it will reach the Newark Penn, even if it delays it will only 2 more passengers.
2. If you insist you are the type you will buy tickets, buy few off peak round trip ticket and have $20 in your hand, if the conductor comes, he has take the punch card for sure and there will be no surcharge and it will also take the same time to take care of each person.
I think thats the only way to signal our ridership volume to the ignorant managers inside the NJTransit panel.
Man, Train ride is really fun!
leave a comment