GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 397 of 436    Print  
The following code fails. Why?
int a = 5;
int b = 5;

object oa = a;
object ob = b;

Debug.Assert(oa == ob, "oa is not equal ob");

  
Total Answers and Comments: 2 Last Update: May 27, 2008     Asked by: Farhan 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 25, 2007 07:17:17   #1  
hkasthuri Member Since: November 2007   Contribution: 3    

RE: The following code fails. Why? int a = 5;
oa ob checks reference equality and thus returns false. If you use oa.Equals(ob) it checks for value equality and thus will return true.
 
Is this answer useful? Yes | No
May 27, 2008 05:40:34   #2  
nikhilrawat23 Member Since: May 2008   Contribution: 15    

RE: The following code fails. Why? int a = 5; int b = 5; object oa = a; object ob = b; Debug.Assert(oa == ob, "oa is not equal ob");
the main reason behind the code failure is using operartor instead of Equal.
when we are using than the refrence object should be same.
means
we are comapring refrence of a and b but instead if we use this code than return true

int a 5;
int b 5;

object o1 a;
object o2 a;

debug.assert(o1 o2 "")

other way----------------

int a 5;
int b 5;

object o1 a;
object o2 b;

debug.assert(o1.Equal(o2))

 
Is this answer useful? Yes | No

 Related Questions

C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#: switch(x){case 0:// do somethingcase 1:// do something in common with 0default:// 
Latest Answer : c# switch allows fall through if and only if in empty case. as long as there is a statement in the case it must  use break or go to to  jump out of the case. ...

Use a conditional attribute on the method, as shown below: class Debug{[conditional("TRACE")]public void Trace(string s){Console.WriteLine(s);}}class MyClass{public static void Main(){Debug.Trace("hello");}}In 
Latest Answer : Well, you cant add the namespace System.Diagnostics.ConditionalAttribute. Actually you need to add the namespace System.Diagnostics and capitalise "Conditional" like so:using System;using System.Diagnostics;namespace Debug{    class ...

C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of 
Latest Answer : This article is good.IntroductionIn this article I am going to share my knowledge on Delegates in C#.This would explain the Delegate using simple examples so that the beginner can understand the same.What is Delegate?Definition:Delegate is type which ...

Yes. Set all references to null and then call System.GC.Collect().If you need to have some objects destructed, and System.GC.Collect() doesn't seem to be doing it for you, you can force finalizers 
Latest Answer : GC.Collect();It is recomended that you should not forcefully call the GC. GC does it in the optimal way, since it knows the inner details like which object actually created inner objects.But some case you may need to force GC to free the scarce memory ...

No. C# does not have macros. Keep in mind that what some of the predefined C macros (for example, __LINE__ and __FILE__) give you can also be found in .NET classes like System.Diagnostics (for example, 
Latest Answer : Ans:No ...

C# has finalizers (similar to destructors except that the runtime doesn't guarantee they'll be called), and they are specified as follows: class C{~C(){// your code}public static void Main() 
Latest Answer : If you are not declare any Main() method in your program then compiler will give you this errors. Basically Main() is the entry point for compiler for execution. One more thing C# ia a case sensitive language so be carefull about the spelling of Main() ...

Original Visual J++ code: public synchronized void Run() {// function body}Ported C# code: class C{public void Run(){lock(this){// function body }}public static void Main() {}}  

You want the lock statement, which is the same as Monitor Enter/Exit: lock(obj) {// code}translates to: try {CriticalSection.Enter(obj);// code} finally {CriticalSection.Exit(obj);}  
Latest Answer : A thread is simply a separate stream of execution that takes place simultaneously with and independently of everything else that might be happening. A thread can synchronize itself with another thread waiting for it to complete.The System.Threading.Thread ...

Use the regasm.exe utility to generate a type library (if needed) and the necessary entries in the Windows Registry to make a class available to classic COM clients. Once a class is registered in the Windows 
Latest Answer : ans: using  regasm.exe  utility ...

In the past, you had to call .ToString() on the strings when using the == or != operators to compare the strings' values. That will still work, but the C# compiler now automatically compares the values 
Latest Answer : You can use a.Equals(b) to compare and return a bool value where both a and b are strings. ...


 Sponsored Links

 
Related Articles

ODP.NET - OracleCommand Object

ODP NET More About the OracleCommand Object Till now we have seen OracleCommand working with OracleDataReader OracleCommand is not simply meant for OracleDataReader It has got a lot of functionality for itself Let us see few of the most commonly used features of OracleCommand in this section We will
 

jQuery Table Row Finished Code

jQuery Table Row Finished Code The Finished Code Our second example page has demonstrated table row striping highlighting tooltips collapsing expanding and filtering Taken together the JavaScript code for this page is mosgoogle geshibot lang php" document ready function var highlighted
 

jQuery Interacting with Other Code

jQuery Interacting with Other Code We learned with our sorting and paging code that we can t treat the various features we write as islands The behaviors we build can interact in sometimes surprising ways; for this reason it is worth revisiting our earlier efforts to examine how they coexist with t
 

jQuery Completed sorting and paging code

Learning jQuery The Finished Code The completed sorting and paging code in its entirety follows mosgoogle geshibot lang php" fn alternateRowColors function tbody tr odd this removeClass even addClass odd ; tbody tr even this removeClass odd addClass even ; return this; ; document
 

Microsoft AJAX Library - Creating Object Members on the Fly

Creating Object Members on the Fly One major difference between OOP in C and ASP NET and OOP in JavaScript is that JavaScript allows creating object members on the fly" This is true for objects and classes that you create yourself and also for JavaScript s own objects and types as well He
 

Microsoft AJAX Library - Object-Oriented JavaScript

Object Oriented JavaScript Objects and classes are implemented differently in JavaScript than in languages such as C VB NET Java or C However when it comes to using them you ll feel on familiar ground You create objects using the new operator and you call their methods or access their fields using t
 

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

Object-Oriented Client-Server Internet

Object Oriented Client Server Internet OCSI Environments as IT Infrastructure Client Server Basics Object Oriented Client Server Internet OCSI environments provide the IT infrastructure for supporting OCSI applications For our purposes infrastructure refers to operating systems networks middleware
 

JavaScript String Object

JavaScript String Object In this JavaScript tutorial you will learn about String Object purpose of string object in JavaScript purpose of string object indexof method lastIndexOf method and substring method along with syntax and example mosgoogle center Purpose of String Object in JavaScript The mai
 

JavaScript Date Object

JavaScript Date Object In this JavaScript tutorial you will learn about date object and methods of date object explained along with syntax and example mosgoogle center JavaScript Date Object Usage of Date Object Date object of Java Script is used to work with date and times General syntax for defini
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape