Skip to content

rahathosen/CSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

csharp

explore micro structure

Format

Array collection initializer

             var number = new[] { 5.0, 6.5, 7.3 };        //! one style array
             Console.WriteLine(number[0]);

            int[] myary = new int[] { 5, 6, 7 };        //! second style array
            Console.WriteLine(myary[1]);


             int[] myary3 = { 5, 6, 7 };               //! third style array
             Console.WriteLine(myary3[2]);
Just main() funcion use the add() function means void main() function call the void add() function
  static void Main(string[] args) => add(50, 60);
  
        static void add()
        {
            int a = 50, b = 60;
            int result = a + b;
            Console.WriteLine(value: result);
            
        }
main() function call the add() function and add() returen the result value to main()
  static void Main(string[] args) => Console.WriteLine(value: add(50, 60));
  
        static int add(int a, int b)
        {
            var result = a + b;
            return result;
        }
pass by value and pass by reference
 static void Main(string[] args)
        {
            //pass by value
            var studentGrade = 75;
            Console.WriteLine("student grade before extra credit {0}", studentGrade);
            giveExtracredit(studentGrade);
            Console.WriteLine("student grade after extra credit {0}", studentGrade);

            
            //pass by reference
            int[] grade = new int[] { 10 };
            Console.WriteLine("Student grade before extra credit {0}", grade[0]);
            giveExtragrade(grade);
            Console.WriteLine("Student grade after extra credit {0}", grade[0]);
            
            
            //ref keyword use to create force to reference
            int studentGrade2 = 75;
            Console.WriteLine("Student grade before extra credit {0}", studentGrade2);
            giveExtracredit2(ref studentGrade2);
            Console.WriteLine("Student grade after exra credit {0}", studentGrade2);
            
            //out keyword
            int add;
            int mult;
            AddMult(5, 10, out add, out mult);
            Console.WriteLine(add);
            Console.WriteLine(mult);


        }
        public static void giveExtracredit(int studentGrade) => studentGrade += 3;

        public static void giveExtragrade(int[] grade) => grade[0] += 3;
        
        public static void giveExtracredit2(ref int studentGrade2) => studentGrade2 += 3;
        
        public static void AddMult(int a, int b, out int add, out int mult)
        {
            add = a + b;
            mult = a * b;

        }
    }

Releases

No releases published

Packages

No packages published

Languages