will this code works fine? or will it gives error?
Object obj=5;
int i=6;
i=i+obj;
Answers were Sorted based on User's Feedback
Answer / naren
object obj=5 this is boxing
int i=6 this is initialization of variable.
i=i+obj; here we can't sum the value type and reference
type.
so,it gives the error.
Is This Answer Correct ? | 10 Yes | 0 No |
//can not applied this because i is value type and obj is
reference type so this will create error
//u can do this
Object obj = 5;
int i = 6;
i = i + Convert.ToInt32(obj);
Is This Answer Correct ? | 8 Yes | 1 No |
Answer / sri4u_926
Defenitly it gives Error bcoz we cannot apply operators for
the type object.
Is This Answer Correct ? | 6 Yes | 1 No |
Answer / somnath nanekar
it will give an error...(we hv to typecast object to int)
Is This Answer Correct ? | 3 Yes | 1 No |
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As Object
Dim i As Int16
obj = 5
i = 6
i = i + obj
MsgBox(i)
End Sub
its working fine the result shows 11
private void button1_Click(object sender, EventArgs e)
{
object obj;
obj = 5;
int i;
i =6;
i = i + Convert.ToInt16(obj);
MessageBox.Show(i.ToString());
}
when you convert the object to int then only working fine
and show result 11
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / deepika
It will give error: "Operator '+' cannot be applied to
operands of type 'int' and 'object'"
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / prakash kesharwani
this definitely work.
since obj as type integer. and also i as integer.
so the output will be 11.
its gives error when obj is type string.
Is This Answer Correct ? | 1 Yes | 3 No |
Httpcontext objects?
what is msl?
What is layout in mvc?
what is mean by versioning? Please answer me. Advance thanks.
How does the 'page lifecycle' of asp.net mvc works?
When using aspx view engine, to have a consistent look and feel, across all pages of the application, we can make use of asp.net master pages. What is asp.net master pages equivalent, when using razor views?
What is side-by-side execution? Can two application one using private assembly and other using Shared assembly be stated as a side-by-side executables
Describe the .net framework architecture.
What is CLR and how it generates native code ?
1 Answers Digital GlobalSoft, Vital Soft,
Hello guyz, I have interview scheduled next week on .Net Framework 1.1? Can any one please provide a) list of interview questions on .net frame work 1.1? b)basic differences between .net framework 1.1 and 2.0 and 3.5 c)the topics that i need to concentrate while preparing Thanks in advance
What is Value type and reference type in .Net
Explain how you can implement Ajax in MVC?