Solved

Check if int variable is empty

Posted on 2009-07-02
1
875 Views
Last Modified: 2012-05-07
Somewhat basic but still a question,

I have a function like this..
   public string function (int _month, int _year) {

I want to fill those two variables with values if they are empty.. how to? I've done something like this but i seem to understand it wrong..

        if (_year == null) _year = DateTime.Now.Year;
        if (_month == null) _month = DateTime.Now.Month;
0
Comment
Question by:dingir
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 200 total points
ID: 24761237
if ((_year == null) || (_year == 0)) _year = DateTime.Now.Year;
if (_month == null) || (_month == 0)) _month = DateTime.Now.Month;
Thats all right!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question