Solved

Check if int variable is empty

Posted on 2009-07-02
1
876 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 …

737 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