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 8226247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:41:56+00:00 2026-06-07T15:41:56+00:00

I was reading on the net ( http://www.codinghorror.com/blog/2005/07/for-best-results-dont-initialize-variables.html ) that we should not initialize

  • 0

I was reading on the net (http://www.codinghorror.com/blog/2005/07/for-best-results-dont-initialize-variables.html) that we should not initialize variables.

Somehow I dont get it. Often I just cannot avoid that. Lets look on a simple example:

public int test(string s)
{
  int start = 0;
  int mod = 2;
  int output = 0;

  foreach (int i in s)
  {
    output = output + (i % mod) + start;
    start++;
  }

  return output;
}

Ok its maybe a nonsense 🙂 But the question is: can I avoid the initialization? Maybe its not possible for mod, because mod have to be 2 from the beginning and it will stay 2. But how about start and output? I just cannot write int start because thats always Error Use of unassigned local variable. Maybe int start = null would be better, but in this case its not gonna work too. So how to avoid this stuff?

  • 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-07T15:41:58+00:00Added an answer on June 7, 2026 at 3:41 pm

    You’ve misread his article. In his article he is specifically talking about initialization of variables with respect to classes. In the case you’ve put forth, your variables should be initialized before they can be used because they’ll be immediately used.

    Edit: Yes, in this specific case the int variables don’t need initialization because the compiler automatically initializes an int to 0, but if this is taken to a different degree with a string or a DateTime, initialization becomes important in the context of a method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a post about mobile web development and ASP.NET MVC here: http://www.hanselman.com/blog/ABetterASPNETMVCMobileDeviceCapabilitiesViewEngine.aspx
Reading the documentation at http://jersey.java.net/nonav/documentation/latest/client-api.html#d4e704 makes me think that ClientFilter s are processed in
I'm reading this article http://www.codeguru.com/Csharp/.NET/net_security/authentication/article.php/c7415/ I still don't understand the concept of Principal (why
I was reading this today: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#default-parameter-values and I can't seem to understand what's happening
This is my code: function get_remote_file_to_cache(){ $sites_array = array(http://www.php.net, http://www.engadget.com, http://www.google.se, http://arstechnica.com, http://wired.com); $the_site=
I was reading http://www.orchardproject.net/docs/Creating-1-n-and-n-n-relations.ashx and could not get the idea, if it is possible
is there any pgp key dumping program like http://www.pgpdump.net/ that also shows the MPI
Reading the article on http://www.jamesward.com/2011/08/23/war-less-java-web-apps on how to embed an app server with your
I was reading this blog post: http://www.shakie.co.uk/ramblings/feature-driven-development-riding-the-waves-of-change/ and came across the part about TestDox:
I was reading about Closure interface here: http://www.php.net/class.closure Then I googled it and couldn't

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.