1

I am trying to translate a Java program to C#. In the Java program there is a line Arrays.fill(used, false);. When googled it, there is Array.Fill<>() in C#. But I am getting an error saying Array does not contain definition for Fill(). Does anybody know how to fix this?

My project is using .NET Framework 4.8.1. I am wondering why I cannot use Array.Fill() function documented in MSDN in my installation of Visual Studio.

My code is using the namespaces 'System', 'System.Collections.Generic', and 'System.Text'.

I have googled it and found one solution as adding 'System.Runtime.dll'. But I cannot find the file in 'ReferenceAssemblies' folder. I have downloaded and installed the .NET Framework from the website directly as well as tried repairing Visual Studio.

0

1 Answer 1

2

This method is available in:

  • .NET: Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8
  • .NET Standard: 2.1

Check that your app targets one of above (not earlier .NET Framework 3.5/4.5 etc).

Sign up to request clarification or add additional context in comments.

6 Comments

The app is targeting .NET Framework 4.8.1.
@thomarjos that means you can't use Array.Fill and should use the alternative from the dupe.
@GuruStron But why is that? Isn't it part of the .NET Framework?
@thomarjos no. It is part of .NET (Core). See this answer
@GuruStron Thank you. That actually fixed it. I didn't which .NET I was supposed to use. I usually use .NET Framework project templates. It was not even mentioned in MSDN. You should write it as a solution so I can mark it.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.