Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:31:39+00:00 2026-06-01T17:31:39+00:00

public string getTime() { StringBuilder RetString = new StringBuilder(); RetString.Append(Hours.ToString().PadLeft(2, ‘0’) + – +

  • 0
   public string getTime()
   {
       StringBuilder RetString = new StringBuilder();
       RetString.Append(Hours.ToString().PadLeft(2, '0') + "-" + Min.ToString().PadLeft(2, '0') + "-" + AMPM.PadLeft(2, '0'));
       return RetString.ToString();
   } 

I’m attempting to return a time (in string format) back to a form string variable using this. I have the user setup to enter a time and the time is stored in this class, and all im doing now is bringing that data to the form im working in. I’ve verified that the data is going into the class and being stored in the variables.

The error i get is :

CSharp_Null

Not really sure what the problem is.
I have the variables declared of course

    private int Hours;
    private int Min;
    private string AMPM;

I have get sets setup:

public int _hours
    {
        get
        {
            return Hours;
        }
        set
        {
            if (value <= 12 && value >= 1)
            {
                Hours = value;
            }
            else
                Hours = 0;
        }
    }

    public int _min
    {
        get
        {
            return Min;
        }
        set
        {
            if (value <= 59 && value >= 1)
            {
                Min = value;
            }
            else
                Min = 0;
        }
    }

    public string ampm
    {
        get
        {
            return AMPM;
        }
        set
        {
            if (AMPM == "AM" || AMPM == "PM")
            {
                AMPM = value;
            }
            else
                AMPM = "";
        }
    }

and my call to the class:

string timefromclass;
timefromclass = timec.getTime();

The only thing that I think it could be would be my call to the class where i store the time is

C_Time time = new C_Time();

but in the other form i setup another one as well.

C_Time timec = new C_Time();

Possibly i’m trying to retrieve the time from an empty instance?

EDIT:

public void setTime(int hours, int min, string aMPM)
    {
        Hours = hours;
        Min = min;
        AMPM = aMPM;

That’s really the only place I assigned that variable anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:31:40+00:00Added an answer on June 1, 2026 at 5:31 pm

    From you code, I assume your AMPM field is null.

    You do not seem to instantiate it anywhere apart from the setter, which you are not calling in your code.

    Initializing it should solve the issue:

    private string AMPM = string.Empty;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public string[] SearchForMovie(string SearchParameter) { WebClientX.DownloadDataCompleted += new DownloadDataCompletedEventHandler(WebClientX_DownloadDataCompleted); WebClientX.DownloadDataAsync(new Uri( http://www.imdb.com/find?s=all&q=ironman+&x=0&y=0 )); string
lot__no is a public string Dim myDelims As String() = New String() {<beginning of
I would like to use substitution feature of donut caching. public static string GetTime(HttpContext
I wrote the following code to get the time public String getTime() { final
I have got this method in my controller. public string GetTime(string zone) { DateTime
public class Song { public string Genre { get; protected set; } public string
public class Mailing { public string To { get; set; } public string AttachmentPath
public class Account { public string Username { get { return Username; } set
Public class AbcViewModel { public string native{get; set;} public string other{get; set;} public List<AbcViewModel>
public class ReflectionBase { public String ParentProperty1 { get; set; } public String ParentProperty2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.