Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

i have a question which is quite simple but yet complicated
for me
my question is why do we use void, if it does not return
anything to the compiler?
if it is used for normal display it can also be done by
what is called Console.Write() or Consol.WriteLine() and if
i do not use void with my method then my compiler throws me
an error. if i return a value say integer then i write
public int fun() display of the result can also be done
here
then why is it so necessary to use void with a function and
why so compiler throw us an error if v don't use void
return type?

Answer Posted / sathish

Just to add on that,
i guess, Compiler basically looks the pre-defined syntax or
format rather than just the keyword, like say, it parses
function as ACCESS MODIFIER RETURNTYPE FUNCTION() e.g.
public void test(). Here ACCESS MODIFIER is optional,
becuase bydefault it is PRIVATE, but return type is
mandatory, that is why, eventhough you don't return any
value, it is mandatory to instruct compilter that, the
function does not return anything.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do extension methods have to be static?

1006


What is difference between Enum and Struct?

979


What are cookies in c#?

952


Explain the difference between abstract class and interface.

1139


What does readonly mean in c#?

979


What operators can be used to cast from one reference type to another without the risk of throwing an exception?

887


How many bytes is a char c#?

867


Is list passed by reference c#?

870


what is inheritance and an example in vb.net and c# of when you might use it?

930


What is the difference between array and arraylist in c#?

1009


How can I process command-line arguments?

957


How do I create a dbml file?

958


Why ienumerable is used in c#?

862


Explain lock, monitors, and mutex object in threading.

899


What is iqueryable?

913