Wednesday, April 24, 2024 :: Login  

Create dummy data in .NET

It is always important to do proper and realistic testing so I have written some flexible but simple dummy data functions to simplify these tasks.

 

Two dimensional string Array

VB

Public Function CreateStringArray(rows As Integer, cols As Integer) As String(,)
	Dim Arrtmp As String(,) = Nothing

	Dim r As Integer
	Dim c As Integer

	Arrtmp = New String(rows - 1, cols - 1) {}
	For r = 0 To rows - 1
		For c = 0 To cols - 1
			If r = 0 Then
				If c > 0 Then
					Arrtmp(r, c) = "Col" & c
				End If
			Else
				If c = 0 Then
					Arrtmp(r, c) = "Row" & r
				Else
					Arrtmp(r, c) = "10"
				End If

			End If
		Next
	Next

	Return Arrtmp
End Function

 

C#

        public string[,] CreateStringArray(int rows, int cols)
        {
            string[,] Arrtmp = null;

            int r;
            int c;

            Arrtmp = new string[rows, cols];
            for (r = 0; r <= rows - 1; r++)
            {
                for (c = 0; c <= cols - 1; c++)
                {
                    if (r == 0)
                    {
                        if (c > 0)
                        {
                            Arrtmp[r, c] = "Col" + c;
                        }
                    }
                    else
                    {
                        if (c == 0)
                        {
                            Arrtmp[r, c] = "Row" + r;
                        }
                        else
                        {
                            Arrtmp[r, c] = "10";
                        }
                    }

                }
            }

            return Arrtmp;
        }

 Usage:

Privacy Policy www.made4dotnet.com 2020

Map IP Address
Powered byIP2Location.com

   Terms Of Use   ::   Privacy Statement   ::   Copyright (c) 2024 www.made4dotnet.com - .NET Development