crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

Is it possible to store different datatypes in one array like Int String Float and Char?
Question Posted on 24 Jul 2020Home >> DotNet >> C# >> Is it possible to store different datatypes in one array like Int String Float and Char?

Is it possible to store different datatypes in one array like Int String Float and Char?
Yes, it is possible to store different datatypes or we can say mixed datatypes in one array. But the array type should be of type object that can store any datatype but also the object of the class as given in below example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace consoleAppExample
{
 class MainProgram
 {
  class SubProgram
  {
   public int EmpId {get; set;}
   public string EmpName { get; set; }
   public override string ToString()
   { return this.Name; }
 }
 static void Main(string[] args)
 {
  //sample of array of object type
  object[] array = new object[3];
  array[0]=1234;
  array[1]="crackyourinterview.com";
  SubProgram subobj=new SubProgram();
  subobj.EmpId =567;
  subobj.EmpName="Adam";
  //Assign object of class to array as 3rd array
  array[2]=subobj;
  }
 }
}
0
0



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

Simplest definition of partial classes and its rules?

Definition of Tuple class with some examples?

Define Race Condition in cSharp?

C#.Net Reserve Words

can we inherit private class level variables in c#






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap