Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Does Array.Clear use default?

Does Array.Clear use default?

Scheduled Pinned Locked Moved C#
csharpdatabasedata-structuresquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Shapira
    wrote on last edited by
    #1

    If one has T[] a = new T[](something); ... Array.Clear(a,0,a.Length); does Array.Clear use default(T)? The documentation for .NET 2.0 and 3.0 suggests that it doesn't (!): public static void Clear(Array array, int index, int length) Sets a range of elements in the Array to zero, to false, or to a null reference (Nothing in Visual Basic), depending on the element type. If Array.Clear really does not use default(T), is there some a base class library method that does this: static void f(Array a, int index, int length) { for (int i = 0; i < a.Length; i++) { a[i] = default(T); } } where T is the type of the array? Maybe this would be something in System.Collections.Generic in order to allow the method's implementation to get at T. It's easy enough to make my own method to do this but I'd just as soon not do it if something already exists in the base class library.

    A 1 Reply Last reply
    0
    • A Andrew Shapira

      If one has T[] a = new T[](something); ... Array.Clear(a,0,a.Length); does Array.Clear use default(T)? The documentation for .NET 2.0 and 3.0 suggests that it doesn't (!): public static void Clear(Array array, int index, int length) Sets a range of elements in the Array to zero, to false, or to a null reference (Nothing in Visual Basic), depending on the element type. If Array.Clear really does not use default(T), is there some a base class library method that does this: static void f(Array a, int index, int length) { for (int i = 0; i < a.Length; i++) { a[i] = default(T); } } where T is the type of the array? Maybe this would be something in System.Collections.Generic in order to allow the method's implementation to get at T. It's easy enough to make my own method to do this but I'd just as soon not do it if something already exists in the base class library.

      A Offline
      A Offline
      AB7771
      wrote on last edited by
      #2

      Wht actually do you want to do?

      Thanks & Regards, Pramod "Everyone is a genius at least once a year"

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups