Sunday, November 26, 2017

How to iterate Object Array with custom data type.

I went through an interview and interviewer asked what will print if I have loop through the object array, where this array contains 3 values  in first index array[0] it has string then arr[1] integer and third arr[2] is class type value.

Let me give you an example with c# console application program.




As you have noticed the output for third array is like "NamespaceName.ClassName".
Here you won't be able to get the id or name from that object. If you want to get the name from that object in this  case please see below example.

public static class PracticalExample1 {
    public static void Method1() {
    var obj = new object[3];
    obj[0] = 1;
    obj[1] = "Ramesh";
    obj[2] = new Employee {
                 Name = "Vijay"
             };
    foreach (var o in obj) {
       Console.WriteLine(o);
    }
 } }

public class Employee {
     public int Id { get; set; }
     public string Name { get; set; }
 
     // By default you can override 3 method in any custom class named ( 1. Equals() 2. GetHasCode() and 3. ToString() )
     // I have to use override the ToString() method to get the name from this class.
     public override string ToString() {
         return this.Name;
     }
 }


Now well be able to fetch the name from the custom class object (Employee class).


Garbage Collector Undestanding

In this article I have shared some points related to .NET Garbage Collector as follows.. 1. Destructor 2. Idisposable interface and Pattern 3. Using block 4. Dispose vs Finalize 5. GC (Garbage Collector) Some key points to remember about GC. 1. GC is a.net framework thread, which run in background. 2. GC check for all the objects which has destructor, if found then it will place them in another list named as Finalization List. 3. GC create two thread, The first thread:
  1. Which are reachable list (All reachable object are clared one after one from the heap list and this it reclaim the memory)
  2. Another which are not (which are not reachable is known as finalization list)
In 2nd thread,
  1. which reads the finalization lists and calls, the each object finalized in separate object.
How does GC Runs when:
  • Gen 0 Object reach ~256KB keep
  • Gen 1 objects reach ~2Meg
  • Gen 2 objects reach ~10meg
  • System memory is low.
What is managed and unmanaged code?
  1. .NET c#,vb Classes are known as Managed Object. All those which has been created using .net language, gc treated as a managed code.
  2. (vb6, com ,windows, connection, files) all these type of code or we can say non .net developed code are known as unmanaged code.
What is finalize method? Note: If your classes is using unmanaged code then start implement finalise method. If your classes is not using unmanaged code then forget about Finalize method call, don't do this at all because it's not required. How garbage collector call the Finalize method. As we all know that we have 3 gen where memory got collected. GC frequently check the Generation-0 bucket.
  1. Checking frequency in the Finalize queue is very less as compare to gen (0,1,2,)      bucket.
  2. By defining the destructor you can define the finalize method.
  3. When Code is complied the distructor will convert into the finalize    automatiocally.  gc treat this as a finalize, Moreover, in .net reflector you can see that after compilation the destructor convert into finalize method.
  4. We can not call directly finalize method because developer don't have any access to finalize .
  5. Only GC has the rights and facility to call the finalize method.
Advantages of using the GC. (Suppose a application uses a costly external resources, then a way to explicitly release the resource before the garbage collector frees the object.  a ->  Define a method to release allocated resources. (mscorlib.dll) Characteristics of Destructor
  1. Destructors (~) cannot be defined in Structs.
  2. Destructors (~) are only used with classes.
  3. Destructor cannot be inherited or overloaded.
  4. Destructor does not take modifiers or have parameters.
  5. Destructor cannot be called. They are invoked automatically.
  6. An instance becomes eligible for destruction when it is no longer possible for any code to use the instance.
  7. The Programmer has no control over when destructor is called because this is determined by Garbage Collector.
  8. Destructor is called when program exits.
  9. Execution of the destructor for the instance may occur at any time after the instance becomes eligible for destruction.
  10. Destructor implicitly calls Finalize on the base class of object.
  I have taken some references from c-sharpcorner.com, stackoverflow, codeproject, pluralsight and through some youtube videos.

Tuesday, October 10, 2017

Don't take bike on rent online from any website of Delhi (www.wheelstreet.com) TrueConnect

                         Don't rent bike from Delhi specially from WheelStreet. 

Reason to not let the bike

1. No good quality Helmet.
2. No good services
3. Fail on commitments/Promises.
4. They don't have latest bullets models.
5. They will not refund your token amount even if they fail to provide you bike.
6. No Guarantee to get back your deposit amount because they will make some nonsense excuses. 

Note: If you want to rent bike then first inspect bike by your own and make sure that you have new engine oil because they are very good in making fake promises.

If you want to know the reason for this then go through my bellow experience with them. Remember, You will be called wise if you learn from other mistakes else no one would be able to help you to get fooled.

We are 6 friends who decided to take 3 bike on rent online with token amount of 5 k prior 15 days to Ladakh trip from one of the disgraced company named  https://www.wheelstreet.com/. When we reached Delhi one day before the trip, We went to their office and said we have advanced booking for 3 bullets (350 cc with the latest model-2017).

See the below conversation with them.

Customer Care: Go to our shop and asked for the bike they will give you 3 bullet with latest model-2017.

Us: We Reached to shop asked for the bike one day before our Ladakh trip.

Vendor: We have only one bike which is 2013 model.

Us:  Now what to do with whom we gonna talk. We need 3 bike and it's your responsibilities to provide bikes for what we have paid.

Vendor : Talk to customer we can't help you out.

CC: They said, We have only one bike available for other two you have to wait.

Us: We said we are struggling from last 2 hours now we want our money back we don't  want to avail service from you, it's your failure not our so give it back but they refuse to give back and finally after 4 hours they said we have arranged two more bike and asked to go another location near in () and again we got 2013 model bullet one is 350 and another is 500 cc). We asked them to give 2017 as what we deal for.

CC: They said we don't have bike now you can manage by your own, we can't provide you 2017 model and also the token amount.

We all were angry , said and help less because we have only two option either accept those bike or lose your token amount.

This is not the end yet, Now I said 2013 model bike's battery is not good at all please change the battery else it will create problem in hills(Ladakh,Jammu kashmir and all) bcz of temperature.

They refuse to change the battery. So, we have to accept it.. This is not the end of our problem.

When we reached to Ambala we halt for 30 minutes after that my bike (500cc) was not starting, some how we manage got one local bullet mechanic and he said the battery is been discharged completely. Secondly, the engine oil is very less how could you go to Ladakh with this much of engine oil, your engine will bust or damage due to insufficient oil.

When we reached Jammu after night halt again same battery problem and that day due to Eid no shops were open we roaming around the jammu to get battery and due to this shit whole day got waste.

Still this is not end yet.
When we came back to Delhi and giving back to vendor they asked the royal en-field mechanic for inspections and annoyingly they said bike need service ,engine got bust have to repair bike and it will cost 20 k. They know that we have flight on same day and we can't wait for longer they were not talking to use nicely, they know that we are outsiders and we can't even touch their hair.

And Earlier manager of wheelstreet said pay from your pocket and when we will back he will reclaim the charges but he final output was we have to let our 15 k deposit and 3 k battery and all extra expenses on bike we paid from our pocket.


As per our experience I will suggest everyone to not led the bike online from any website. Just go to shop one day before your trip and take bike accordingly else you will be always in loss.




Thursday, August 3, 2017

My Ladakh Experience

Nature is truly mesmerizing and magic is spread everywhere. You just have to gaze the nature and what you can only do is believe.
Had not seen a clearer sky, water more blue, hills so majestic and snow so white. Seems like one of the places straight out of your dreams, Ladhak is truly a beauty with nature in its most raw and untouched forms. 
If you think paradise does not exists, pay a visit to Ladakh once which speaks for itself. You cannot realize its enchanting beauty until you see it for yourself.

#Glimpse #Nature #Ladakh #Road #Trip #From#Delhi#to#Ladakh

























 

Wednesday, November 2, 2016

12 Best Google Chrome Extensions

1. Adblock Plus
2. uBlock Origin
3. Blur
4. Hola Better Internet
5. LastPass
6. WOT
7. Click & Clean
8. Save to Pocket
9. Awesome Screenshot
10.Chrome Remote Desktop
11.StayFocused
12.Pixlr Editor

Friday, July 18, 2014

Popular Posts