Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,239 questions

56,142 answers

573 users

How to insert values into a string using string interpolation in C#

4 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int csharp = 1, cpp = 2, java = 3;

            string s = $"c# = {csharp} c++ = {cpp} java = {java}";

            Console.WriteLine(s);
        }
    }
}


/*
run:

c# = 1 c++ = 2 java = 3

*/

 



answered Mar 8, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3 };

            string s = $"c# = {arr[0]} c++ = {arr[1]} java = {arr[2]}";

            Console.WriteLine(s);
        }
    }
}


/*
run:

c# = 1 c++ = 2 java = 3

*/

 



answered Mar 8, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 10;

            string s = $"a = {n*13} b = {n+200}";

            Console.WriteLine(s);
        }
    }
}


/*
run:

a = 130 b = 210

*/

 



answered Mar 8, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = $"result = {Calc(5)}";

            Console.WriteLine(s);
        }
        static int Calc(int n)
        {
            return n * n * n;
        }
    }
}


/*
run:

result = 125

*/

 



answered Mar 8, 2017 by avibootz
edited Mar 8, 2017 by avibootz

Related questions

1 answer 195 views
1 answer 124 views
124 views asked Jan 22, 2023 by avibootz
1 answer 239 views
2 answers 274 views
1 answer 148 views
...