473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

please explain this program

Expand|Select|Wrap|Line Numbers
  1. class test
  2. {
  3.         static void show(params object[] b)
  4.        {
  5.           console.WriteLine(b.GetType().FullName);
  6.  
  7.          console.WriteLine(b.length);
  8.          console.WriteLine(b[0]);
  9.     }
  10.   public static void Main()
  11.   {
  12.    Object a[]={1,"hi",4000};
  13.    show((Object)a);
  14. }
  15.  
  16. }
  17.  
Output
======
System.Object[]
1
System.Object[]

How its coming i don't Know.Please explain this.

What is the use of GetType()

What is the use of FullName
Feb 19 '08 #1
2 1190
int08h
28
OK, I will explain all key points

first, the method name
static void show(params object[] b)
the "params" keyword allows a method to have variable-count arguments, you can call it like
static void show(1, 2, 3)
this invocation gives the method 3 arguments (1, 2 and 3)
in the method arguments is encapsulated in an array, so b is an array of object

second, the GetType() method returns the type, like:
string str;
so str.GetType() will return System.String
int i;
i.GetType() will return System.Int32

third, the FullName property of type Type gives the full name (namespace+type) of the type, some thing as
string is System.String
int is System.Int

so the first line outputs the full name of the type of arugment b, it is previously said that b is an array of object, so its type is
System.Object[]

forth, considering the length of b, it is a bit more complex
Object a[]={1,"hi",4000};
show(a);
the length will be 3(1, "hi" and 4000)
however, you conert a (array of object) to a object, so in method test, b only contains an object, this object is an array of object (everything is an object)

so if you add a line said:
Console.Writeline(((object[])b[0]).Length)
it will be 3

at last, the last output line System.Object[]
since it is previously said that b in this case is a array of object in which the first element is also an array of object, therefore b[0] is Object[]
the last output calls ToString() method of b[0], so it calls ToString() on an instance of object[], it just returns "System.Object[]"
Feb 19 '08 #2
Thank You now i understood
Feb 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Abhish | last post by:
HI All ,:) I am a VC++ programmer,and some time My <b>Acumen</b> ask Microsofts VC++ (Visual Studio VC++ 6.0 )complier to complile my <b>senseless programs </b> ! :) <i><b> See what I have...
1
by: Yash | last post by:
Hi, Can someone please explain to me what the StreamReader.DiscardBufferedData method does? The documentation says "Use DiscardBufferedData to seek to a known location in the underlying stream...
9
by: hope | last post by:
Hi Access 97 I'm lost on this code please can you help ================================= Below is some simple code that will concatenate a single field's value from multiple records into a...
12
by: Sanjeev | last post by:
Output of followin program at Turbo C++ 3.0 is 7 ( Not 2 or 3). Please explain why ? //////////////////////////////////////////////// #include<stdio.h> #include<string.h> void main() {
6
by: Buck Rogers | last post by:
Hi guys! Love your work! The below program is from K&R2, p22. ================================= #include <stdio.h> /* count digits, white space, others */ main() {
22
by: Jaspreet | last post by:
I was recently asked this question in an interview. Unfortunately I was not able to answer it and the interviewer made a decision on my C strengths (or weekness) based on this single question and...
0
by: raa abdullah | last post by:
Overview A conflict-serializbility\recoverability checker, SCR, is a program that takes in a schedule and outputs 2 decisions: Conflict serialzable or Not confilict serializable AND Recoverable or...
0
by: wb5plj | last post by:
Hi I am having a problem passing some sql to the db2cmd via ant. This is very confusing as I am doing this exact thing elseware with no problem (just differant sql, and I have verified the sql is...
4
by: fatboySudsy | last post by:
Hi, I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. ...
2
by: sathishc58 | last post by:
Hi All Please explain why strlen returns() "16" as output here and explain the o/p for sizeof() as well main() { char a={'a','b','c'}; printf("strlen=%d\n", strlen(a));...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.