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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:48:00+00:00 2026-05-26T01:48:00+00:00

I often come across situations when I need to use the same variable but

  • 0

I often come across situations when I need to use the same variable but converted to a different type.

for example:

string port;
...
ValidatePort(int port);

Here in ValidatePort I need to use the same variable port but its type should be integer. In order to do that I need first to convert original port to int and use a temporary variable like iPort or something similar to pass it then to ValidatePort

This is not the only case of naming collision and in every other situation I used different approaches (if I needed a string I called it variableName + String or some other endings)

Is there a naming convention in C# for that or a common approach for naming variables that are similar but of different types?

  • 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-05-26T01:48:00+00:00Added an answer on May 26, 2026 at 1:48 am

    I would say it is wise to make it obvious what a variable is by looking at it.

    var time;
    

    you have no idea what that represents. It could be any of these:

    int time; // number of seconds
    DateTime time;
    TimeSpan time;
    

    I would say

    int port = 7;
    string portAsString = port.toString();
    

    but for your code above, there is no problem with just calling it port as this code is perfectly valid:

    string port = "7";
    
    int portAsInteger = int.parse(port); // If you need a temporary variable
    
    myMethod(int.parse(port)); // You can use variable 'port' twice as scope is different
    myMethod(portAsInteger);
    
    public void myMethod(int port) { .... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we often come across a scenario where in we need to pass a String
I often come across the term 'named type' in C#. What does it mean?
Over the last few months I've often come across the same Design obstacles when
I've come across a problem, that is probably seen pretty often, but has never
I have often come across situations like :- try{ ... stmts ... } catch(Exception
Often times I come across situations where I want to execute a jQuery function
I often come across web applications that expose internal database primary keys through forms
When using JDBC, I often come across constructs like ResultSet rs = ps.executeQuery(); while
when i read through source files of opensource projects i often come across some
Quite often I come across a nice looking or functional website, and wonder what

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.