Convert Object to Int - CSharp System

CSharp examples for System:Object

Description

Convert Object to Int

Demo Code


using System.Net;
using System.IO;//w ww  .  j av  a2  s .  com
using System.Text.RegularExpressions;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System;

public class Main{

        public static int GetInt(object obj)
        {
            if (obj == null)
            {
                return 0;
            }
            int result = 0;
            int.TryParse(obj.ToString(), out result);
            return result;
        }
}

Related Tutorials