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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:29:20+00:00 2026-06-04T04:29:20+00:00

Here is a simple example of a one-lined IF statement. if(condition) something = blah;

  • 0

Here is a simple example of a one-lined IF statement.

if(condition)
    something = "blah";

I find myself using them often for simple things, but later on while expanding the application, expanding them to a multi-lined if statements

if(condition)
{
    something = "blah;
    somethingElse = "blar";
}

But I find this quite frustrating because I have to go through several steps to do so. When I enter the first brace, my code formatter (Visual Studio? Resharper?) proceeds to enter a second (closing) brace, and formats it like so:

if(condition) { }
something = "blah";

I then have to select and remove the closing brace, and do my own formatting to get it to look correct.

Is there a way that I can conveniently have resharper or visual studio automatically enter the braces around the one-lined IF statement? e.g: I entered an opening brace after the condition and it automatically formatted it like

if(condition)
{
    something = "blah";
}
  • 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-04T04:29:21+00:00Added an answer on June 4, 2026 at 4:29 am

    What you can do is define a new snippet that is exactly like the if code snippet without the “if ($expression)” part:

    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
        <CodeSnippet Format="1.0.0">
            <Header>
                <Title>multiif</Title>
                <Shortcut>multiif</Shortcut>
                <Description>Code snippet for multiline if statement</Description>
                <Author>Microsoft Corporation</Author>
                <SnippetTypes>
                    <SnippetType>Expansion</SnippetType>
                    <SnippetType>SurroundsWith</SnippetType>
                </SnippetTypes>
            </Header>
            <Snippet>
                <Declarations>
                    <Literal>
                        <ID>expression</ID>
                        <ToolTip>Expression to evaluate</ToolTip>
                        <Default>true</Default>
                    </Literal>
                </Declarations>
                <Code Language="csharp"><![CDATA[
        {
            $selected$ $end$
        }]]>
                </Code>
            </Snippet>
        </CodeSnippet>
    </CodeSnippets>
    

    Then you can import this snippet into visual studio by:

    1. Select Code Snippet Manager… from the Tools menu.
    2. Click on the Import… button.
    3. Navigate to your new snippet file.

    or:
    Copy your new snippet file into C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#

    You can then select the body of your single line if statement in your c# file, right click and select Surround With… then select your new snippet.

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

Sidebar

Related Questions

I am learning and trying simple example using node.js and mongoskin. here is my
This problem is not readily reproducible in a simple example here but was wondering
I can't get past this issue I am having. Here's a simple example: class
I'm studying webrat and cucumber and trying to create simple example. Here is my
I have a simple java project (adapted from the example here ), which is
Here's a very simple example of what I see: jrunscript -f - js> var
I'm trying to do very simple example of a UINavigationController. Here is my code:
I have a simple question related to one-line programming. First an example: function test(a)
Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
For example Input <url wiki=https://wiki.archlinux.org/index.php/Main_Page forums=https://bbs.archlinux.org/> Desired output <url wiki=https://wiki.archlinux.org/index.php/Main_Page forums=https://bbs.archlinux.org/> Here's a sample

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.