Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
Implicit Type Casting
Next article icon

C# | Implicitly Typed Arrays

Last Updated : 23 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Implicitly typed arrays are those arrays in which the type of the array is deduced from the element specified in the array initializer. The implicitly typed arrays are similar to implicitly typed variable. In general, implicitly typed arrays are used in the query expression.
Important points about implicitly typed arrays: 
 

  • In C#, the implicitly typed arrays do not contain any specific data type.
  • In implicitly typed array, when the user initializes the arrays with any data type then compiler automatically convert these arrays into that data type.
  • Implicitly typed arrays generally declared using var keyword, here var does not follow []. For Example:
     
var iarray = new []{1, 2, 3};
  • All types of array-like 1-D, Multidimensional, and Jagged Arrays etc. can be created as an implicitly typed array.
  • In C#, it is necessary to initialize implicitly typed array and have the same data type.

Example 1: Below program illustrates how to use 1-Dimensional Implicitly typed array. 
 

CSharp




// C# program to illustrate
// 1-D implicitly typed array
using System;
 
public class GFG {
 
    // Main method
    static public void Main()
    {
 
        // Creating and initializing 1-D
        // implicitly typed array
        var author_names = new[] {"Shilpa", "Soniya",
                                  "Shivi", "Ritika"};
 
        Console.WriteLine("List of Authors is: ");
 
        // Display the data of the given array
        foreach(string data in author_names)
        {
            Console.WriteLine(data);
        }
    }
}
 
 
Output: 
List of Authors is:  Shilpa Soniya Shivi Ritika

 

Example 2: Below program illustrate the use of Multidimensional implicitly typed arrays. 
 

CSharp




// C# program to illustrate
// 2-D implicitly typed array
using System;
 
public class GFG {
 
    // Main method
    static public void Main()
    {
 
        // Creating and initializing
        // 2-D implicitly typed array
        var language = new[, ] { {"C", "Java"},
                            {"Python", "C#"} };
 
        Console.WriteLine("Programming Languages: ");
  
        // taking a string
        string a;
 
        // Display the value at index [1, 0]
        a = language[1, 0];
        Console.WriteLine(a);
 
        // Display the value at index [0, 2]
        a = language[0, 1];
        Console.WriteLine(a);
    }
}
 
 
Output: 
Programming Languages:  Python Java

 

Example 3: Below code demonstrate the use of Implicitly typed jagged arrays.
 

CSharp




// C# program to illustrate
// implicitly typed jagged array
using System;
 
class GFG {
 
    // Main method
    static public void Main()
    {
 
        // Creating and initializing
        // implicitly typed jagged array
        var jarray = new[] {
            new[] { 785, 721, 344, 123 },
            new[] { 234, 600 },
            new[] { 34, 545, 808 },
            new[] { 200, 220 }
        };
 
        Console.WriteLine("Data of jagged array is :");
 
        // Display the data of array
        for (int a = 0; a < jarray.Length; a++) {
            for (int b = 0; b < jarray[a].Length; b++)
                Console.Write(jarray[a][b] + " ");
            Console.WriteLine();
        }
    }
}
 
 
Output: 
Data of jagged array is : 785 721 344 123  234 600  34 545 808  200 220

 



Next Article
Implicit Type Casting
author
ankita_saini
Improve
Article Tags :
  • C#
  • CSharp-Arrays

Similar Reads

  • Implicit Type Casting
    In programming, data types are the backbone of variable definition and manipulation. Implicit type casting, a fundamental concept in programming languages, involves the automatic conversion of data from one type to another by the compiler. In this article, we will dive deep into implicit type castin
    6 min read
  • Implicit and Explicit type casting
    In programming, type casting is a way to convert data from one type to another. Implicit type casting happens automatically, while explicit type casting requires manual intervention. This article explores the differences between implicit and explicit type casting, their uses, benefits, and considera
    6 min read
  • C++ Omit Array Size
    Prerequisite: Array in C++ The array is a type of data structure that can store data of similar data types. The most significant feature is fixed size. There are two conditions by which we can check the initialization of the array. Methods for Declaring Array 1. Declaring size during initialization:
    2 min read
  • C# | Type.IsArrayImpl() Method
    Type.IsArrayImpl() Method is used when overridden in a derived class, implements the IsArray property and determines whether the Type is an array. Syntax: protected abstract bool IsArrayImpl (); Return Value: This method returns true if the Type is an array otherwise, false. Below programs illustrat
    2 min read
  • One Dimensional Arrays in C
    In C, an array is a collection of elements of the same type stored in contiguous memory locations. This organization allows efficient access to elements using their index. Arrays can also be of different types depending upon the direction/dimension they can store the elements. It can be 1D, 2D, 3D,
    5 min read
  • One Dimensional Arrays in C++
    One-dimensional arrays are like a row of boxes where you can store things where each box can hold one item, such as a number or a word. For example, in an array of numbers, the first box might hold 5, the second 10, and so on. You can easily find or change what's in each box by referring to its posi
    6 min read
  • C# | Implicitly Typed Local Variables - var
    Implicitly typed variables are those variables that are declared without specifying the .NET type explicitly. In an implicitly typed variable, the type of the variable is automatically deduced at compile time by the compiler from the value used to initialize the variable. The implicitly typed variab
    4 min read
  • Arrays in Objective-C
    An Array is a data structure that holds similar types of data in contiguous memory. The Objective-C array is a single variable array that is used to store different types of elements in the array. Also, we can access the objective-c array using an index. It is quite similar to the C programming lang
    5 min read
  • Solidity - Reference Types
    Solidity references store and modify complicated data structures including arrays, structs, maps, and strings. These data types hold a reference to the data's memory or storage location, unlike value types like integers and booleans. Reference types are vital for developing complicated Ethereum smar
    6 min read
  • Pointer to an Array in C++
    Pointers in C++ are variables that store the address of another variable while arrays are the data structure that stores the data in contiguous memory locations. In C++, we can manipulate arrays by using pointers to them. These kinds of pointers that point to the arrays are called array pointers or
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences