Essential C# Code - fabulouscode

Wednesday, April 17, 2019

Essential C# Code





Remove Last Character from a C# String
  1. /** Remove sample **/  
  2. string founder = "Mahesh Chand is a founder of C# Corner!";  
  3. // Remove last character from a string  
  4. string founderMinus1 = founder.Remove(founder.Length - 1, 1);  
  5. Console.WriteLine(founderMinus1);  

How can I convert String to Int?

HangerQty = Int32.Parse(dt.Rows[i]["HangerQty"].ToString()); 
int x = Int32.Parse(TextBoxD1.Text);

Find text in string with C#

string s = "Together we can do so much!";
Now let’s say you need to find the word “much”
if (s.Contains("much") == true) {
   Console.WriteLine("Word found!");
}

String Replace in C#


string q= "my name's is tuhin";
string r = q.Replace("'", "");


String Trim in C#

String.Trim()


string x = " Hello World! ";

string y = x.Trim(); // "Hello World!"
string q = "{(Hi!*";
string r = q.Trim( '(', '*', '{' ); // "Hi!"

String.TrimStart() and String.TrimEnd()
string q = "{(Hi*";
string r = q.TrimStart( '{' ); // "(Hi*"
string s = q.TrimEnd( '*' ); // "{(Hi"

Date Time Convert::


DateTime dateString = Convert.ToDateTime(Date);

var TODCreateDate = dateString.ToString("yyyy-M-dd");

Convert Varchar to integer


Convert.ToInt32();

Example:
Convert.ToInt32(Bn.IssueQty);


How do I get the last four characters from a string in C#


Soulation :: 


string str = "1110000";
string lastFourDigits = str.Substring((str.Length - 4), 4);


alternative to nested if statements c#


if (saveinfo.ExColorName != Bn.ColorName && saveinfo.ExFabricType != Bn.FabricTypeName && saveinfo.ExFabricDia != Bn.FabricDia && saveinfo.ExFabricGSM != Bn.FabricDia)
                    {
                        bi.MgsId = 104;
                        bi.AppStatus = "attack";
                        bi.Messege = ("Gray Blance Not Found !! Please contact Store Concern !!");
                        lDn.Add(bi);

                    }
==================================================
bool isBlue = sky.Color == Colors.Blue;
bool containsOxygen = sky.Atoms.Contains("oxygen") && sky.Bonds.Type == Bond.Double;
bool canRain = sky.Abilities.Contains("rain");
if(isBlue)
{
}
if(containsOxygen)
{
}
if(canRain)
{
}
if(!isBlue && !containsOxygen && !canRain)
{
}

No comments:

Post a Comment

I am Safiqul Islam Tuhin